Uncategorized

How To Create Tables in HTML

Introduction

A table is a set of data organized by rows and columns. Tables are useful to show connections between data types, e.g. B. products and their costs, employment and employment data or flights and departure times. In this tutorial, you’ll create a table using HTML, customize it by adding a desired number of rows and columns, and add row and column headings to make your table easier to read.

Prerequisites

  • Familiarity with HTML. If you are unfamiliar with HTML or need a refresher, you can check out the first three tutorials in our how-to series on creating a website using HTML.
  • An index.html file for practicing creating HTML tables . If you don’t know how to create an index.html file, please follow the instructions in our short tutorial How to set up your HTML project.

Basics of HTML tables

An HTML table is created with an opening

tag and a closing

tag. Within these tags, data is organized into rows and columns using

tags to open and close table rows and

tags to open and close table data.

Reading: How to create a website using table

Table row tags are used to create

tags use a range of dates. Within table opening and closing

tags, table data opening and closing

tags are used to organize data into columns.

See also  How to Register a Domain Name (and get it for FREE) in 2023

As an example, here is a table with two rows and three columns :

Column 1 Column 2 Column 3
Column 1 Column 2 Column 3

To see how HTML tables work in practice, add the above code snippet in the index. html file or any other HTML file you will use for this tutorial.

Save the file and reload it in the browser to check your results. (For instructions on how to load the file into your browser, please visit this step of our HTML elements tutorial.)

Your web page should now have a table with three columns and two rows:

Table with 3 columns, 2 rows

To add an extra row, add the highlighted

element to the end of your table:

Column 1 Column 2 Column 3
Column 1 Column 2 Column 3
Column 1 Column 2 Column 3

See also: How to Create a Real Estate Website with WordPress

Save your results and review them in your browser . You should get something like this:

3 columns and 3-row table

To add another column, try inserting an additional table data element

in each of the

elements of the table row:

Column 1 Column 2 Column 3 Column 4
Column 1 Column 2 Column 3 Column 4
Column 1 Column 2 Column 3 Column 4

Save your results and check them in your browser. Your web page should display a table with three rows and four columns:

Webpage displays table with three rows and four columns

Adding a border to a table

In general, tables should be styled with CSS. If you are unfamiliar with CSS, you can use HTML to add light styling by adding the attributes to the

element. For example, you can add a border to the table with the Border attribute:

Row 1 Row 2 Row 3
Row 1 Row 2 Row 3

Add the highlighted border attribute to your table and check your results in the browser. (You can delete your index.html file and paste the HTML code snippet above.) Save your file and load it into the browser. Your table should now have a border around each of your rows and columns, like this:

Webpage displays table with border

Adding headings to rows and columns

Headings can be added to rows and columns to make tables easier to read . Table headings are automatically formatted with bold and centered text to visually distinguish them from table data.Headings also make tables more accessible by helping users using screen readers navigate table data.

Headings are added through the use of opening and closing

tags. To add column headings you need to add a new

element at the top of your table where you can add the column names using

tags.

See also: How to Make Money on YouTube in 2023: 7 Top Tips

Delete the index.html file and add a Add row of column headers with the following code snippet:

Column Header 1 Column Header 2 Column Header 3

Save the index.html file and reload it in your browser. You should get something like this:

Web page with HTML column headings

Your web page should display a single row with column headings. Notice that the first column heading is blank. You can add a column header here if you want.

To add row headers, you must add opening and closing

tags as the first element in each

element of a table row. Add the row headings and dates by inserting the highlighted code snippet below between the closing

and

tags of the table in your index.html file:

Column Header 1 Column Header 2 Column Header 3
Row Header 1 Data Data Data
Row Header 2 data data data
Row header 3 data Data Data

Save the index.html file and reload it in your browser. You should get something like this:

Webpage displaying table with columns - and row headers

You should now have a table with three column headers and three row headers.

Conclusion

In this tutorial you can have an HTML Created a table, added additional rows and columns, and created row and column headings.

If you are interested in learning more about HTML, you can check out our tutorial series How To Build a Website With HTML . To learn how to use CSS to style HTML elements (including tables), please visit our How To Build a Website With CSS tutorial series.

See also: New Grad Nursing (RN) Resume Examples & Guide

.

See also  How to Select the Best Domain Registrar (Our Recommendations)

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button