Javatpoint Logo
Javatpoint Logo

HTML Table

HTML table tag is used to display data in tabular form (row * column). There can be many columns in a row.

HTML tables are used to manage the layout of the page e.g. header section, navigation bar, body content, footer section etc. But it is recommended to use div tag over table to manage the layout of the page .


HTML Table Tags

TagDescription
<table>It defines a table.
<tr>It defines a row in a table.
<th>It defines a header cell in a table.
<td>It defines a cell in a table.
<caption>It defines the table caption.
<colgroup>It specifies a group of one or more columns in a table for formatting.
<col>It is used with <colgroup> element to specify column properties for each column.
<tbody>It is used to group the body content in a table.
<thead>It is used to group the header content in a table.
<tfooter>It is used to group the footer content in a table.

HTML Table Example

Let's see the example of HTML table tag. It output is shown above.

Test it Now

Output:

First_NameLast_NameMarks
SonooJaiswal60
JamesWilliam80
SwatiSironi82
ChetnaSingh72

In the above html table, there are 5 rows and 3 columns = 5 * 3 = 15 values.


HTML Table with Border

There are two ways to specify border for HTML tables.

  1. By border attribute of table in HTML
  2. By border property in CSS

1) HTML Border attribute

You can use border attribute of table tag in HTML to specify border. But it is not recommended now.

Test it Now

Output:

First_NameLast_NameMarks
SonooJaiswal60
JamesWilliam80
SwatiSironi82
ChetnaSingh72

2) CSS Border property

It is now recommended to use border property of CSS to specify border in table.

Test it Now

You can collapse all the borders in one border by border-collapse property.

Test it Now

Output:

Name Last Name Marks
SonooJaiswal60
JamesWilliam80
SwatiSironi82
ChetnaSingh72

HTML Table with cell padding

You can specify padding for table header and table data by two ways:

  1. By cellpadding attribute of table in HTML
  2. By padding property in CSS

The cellpadding attribute of HTML table tag is obselete now. It is recommended to use CSS. So let's see the code of CSS.

Test it Now

Output:

Name Last Name Marks
SonooJaiswal60
JamesWilliam80
SwatiSironi82
ChetnaSingh72

HTML Table with colspan

If you want to make a cell span more than one column, you can use the colspan attribute.

Let's see the example that span two columns.

CSS code:

HTML code:

Test it Now

Output:

Name Mobile No.
Ajeet Maurya 7503520801 9555879135

HTML Table with rowspan

If you want to make a cell span more than one row, you can use the rowspan attribute.

Let's see the example that span two rows.

CSS code:

HTML code:

Test it Now

Output:

NameAjeet Maurya
Mobile No.7503520801
9555879135

HTML table with caption

HTML caption is diplayed above the table. It must be used after table tag only.

Test it Now

Styling HTML table even and odd cells

CSS code:

Test it Now

Output:

html table even and odd

Supporting Browsers

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<table>YesYesYesYesYes
Next TopicHTML Lists




Please Share

facebook twitter google plus pinterest tumbler

Learn Latest Tutorials