HTML <table>Tag


Examples

A simple HTML table with two columns and two rows:

<table border="1"> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$80</td> </tr> </table>

Try it Yourself »
(See more examples at the bottom of the page)

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the <table> tag.


Tag Definition and Usage Instructions

The <table> tag defines an HTML table.

An HTML table includes a <table> element, one or more<tr>、<th>and<td>elements.

The <tr> element defines a table row, the <th> element defines a table header, and the <td> element defines a table cell.

More complex HTML tables may also include <caption>, <col>, <colgroup>, <thead>, <tfoot>, and <tbody> elements.


Differences Between HTML 4.01 and HTML5

In HTML5, only the 'border' attribute is supported, and only the value '1' or '' is allowed.


Attributes

Attribute Value Description
align left
center
right
Not supported in HTML5. Deprecated in HTML 4.01.Specifies the alignment of a table relative to the surrounding elements.
bgcolor rgb(x,x,x)
#xxxxxx
colorname
Not supported in HTML5. Deprecated in HTML 4.01.Specifies the background color of the table.
border 1
""
Not supported in HTML5.Specifies whether the table cells have borders.
cellpadding pixels Not supported in HTML5.Specifies the white space between the cell edge and its content.
cellspacing pixels Not supported in HTML5.Specifies the white space between cells.
frame void
above
below
hsides
lhs
rhs
vsides
box
border
Not supported in HTML5.Specifies which part of the outside border is visible.
rules none
groups
rows
cols
all
Not supported in HTML5.Specifies which part of the inside border is visible.
summary text Not supported in HTML5.Specifies a summary of the table.
width pixels
%
Not supported in HTML5.Specifies the width of the table.


Global Attributes

The <table> tag supportsthe HTML Global Attributes.。


Event Attributes

The <table> tag supportsthe HTML Event Attributes.。


Examples

Try it Yourself - Examples

Headings in a table
This example demonstrates how to display table headings.

Empty cells
This example demonstrates how to use '&nbsp;' to handle cells with no content.

Table with a caption
This example demonstrates a table with a caption.

Tags inside a table
This example demonstrates how to display elements inside other elements.

Table cells that span rows or columns
This example demonstrates how to define table cells that span rows or columns.


Related Articles

HTML Tutorial:HTML Tables

HTML DOM Reference:Table Object

HTML Table Generator:Online HTML Table Generator

Other Extensions