The <table> represents tabular data — that is, information presented in a two-dimensional table comprised of rows and columns of cells containing data.
| Content categories | Flow content |
|---|---|
| Permitted content | |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts flow content |
| Permitted ARIA roles | Any |
| DOM interface | HTMLTableElement |
This element includes the global attributes. The following attributes listed on this page are now deprecated.
align
<table> element should be styled using CSS. Set margin-left and margin-right to auto or margin to 0 auto to achieve an effect that is similar to the align attribute.middle, absmiddle, and abscenter values as synonyms of center, in quirks mode only.bgcolor
| black = "#000000" | green = "#008000" | ||
| silver = "#C0C0C0" | lime = "#00FF00" | ||
| gray = "#808080" | olive = "#808000" | ||
| white = "#FFFFFF" | yellow = "#FFFF00" | ||
| maroon = "#800000" | navy = "#000080" | ||
| red = "#FF0000" | blue = "#0000FF" | ||
| purple = "#800080" | teal = "#008080" | ||
| fuchsia = "#FF00FF" | aqua = "#00FFFF" |
<table> element should be styled using CSS. Use the background-color property in CSS to create an effect that is similar to the bgcolor attribute.border
frame attribute is set to void. <table> element should be styled using CSS. To create an effect similar to the border attribute, the border, border-color, border-width and border-style CSS properties should be used.cellpadding
<table> element should be styled using CSS. To create an effect similar to the cellpadding attribute, apply the border-collapse property to the <table> element, with its value set to collapse, and the padding property to the <td> element.cellspacing
<table> element should be styled using CSS. To create an effect similar to the cellspacing attribute, apply the border-spacing property to the <table> element. Border-spacing does not have any effect if border-collapse is set to collapse.frame
| above | below | ||
| hsides | vsides | ||
| lhs | rhs | ||
| border | box | ||
| void |
<table> element should be styled using CSS. To create an effect similar to the frame attribute, use the border-style and border-width properties.rules
<thead>, <tbody> and <tfoot> elements) and between column groups (defined by the <col> and <colgroup> elements) only;summary
<caption> instead. The summary attribute is not mandatory and may be omitted when a <caption> element fulfills its role. <caption> element.<details> element, inside the table's <caption> element.<table> element in a <figure> element and add the description in prose next to it.<table> element in a <figure> element and add the description in prose inside a <figcaption> element.<th> and <thead> elements).width
<table>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
<tr>
<td>Jane</td>
<td>Doe</td>
</tr>
</table>
<p>Simple table with header</p>
<table>
<tr>
<th>First name</th>
<th>Last name</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
<tr>
<td>Jane</td>
<td>Doe</td>
</tr>
</table>
<p>Table with thead, tfoot, and tbody</p>
<table>
<thead>
<tr>
<th>Header content 1</th>
<th>Header content 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Body content 1</td>
<td>Body content 2</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Footer content 1</td>
<td>Footer content 2</td>
</tr>
</tfoot>
</table>
<p>Table with colgroup</p>
<table>
<colgroup span="4"></colgroup>
<tr>
<th>Countries</th>
<th>Capitals</th>
<th>Population</th>
<th>Language</th>
</tr>
<tr>
<td>USA</td>
<td>Washington, D.C.</td>
<td>309 million</td>
<td>English</td>
</tr>
<tr>
<td>Sweden</td>
<td>Stockholm</td>
<td>9 million</td>
<td>Swedish</td>
</tr>
</table>
<p>Table with colgroup and col</p>
<table>
<colgroup>
<col style="background-color: #0f0">
<col span="2">
</colgroup>
<tr>
<th>Lime</th>
<th>Lemon</th>
<th>Orange</th>
</tr>
<tr>
<td>Green</td>
<td>Yellow</td>
<td>Orange</td>
</tr>
</table>
<p>Simple table with caption</p>
<table>
<caption>Awesome caption</caption>
<tr>
<td>Awesome data</td>
</tr>
</table>
By supplying a <caption> element whose value clearly and concisely describes the table's purpose, it helps the people decide if they need to read the rest of the table content or skip over it.
This helps people navigating with the aid of assistive technology such as a screen reader, people experiencing low vision conditions, and people with cognitive concerns.
Although the scope attribute is obsolete in HTML5, many screen readers rely on the attribute to programmatically replicate the visual associations a person not using a screen reader may be able to infer about a cell's position.
<table>
<caption>Color names and values</caption>
<tbody>
<tr>
<th scope="col">Name</th>
<th scope="col">HEX</th>
<th scope="col">HSLa</th>
<th scope="col">RGBa</th>
</tr>
<tr>
<th scope="row">Teal</th>
<td><code>#51F6F6</code></td>
<td><code>hsla(180, 90%, 64%, 1)</code></td>
<td><code>rgba(81, 246, 246, 1)</code></td>
</tr>
<tr>
<th scope="row">Goldenrod</th>
<td><code>#F6BC57</code></td>
<td><code>hsla(38, 90%, 65%, 1)</code></td>
<td><code>rgba(246, 188, 87, 1)</code></td>
</tr>
</tbody>
</table>
Providing a declaration of scope="col" on a <th> element will help describe that the cell is at the top of a column. Providing a declaration of scope="row" on a <td> element will help describe that the cell is the first in a row.
Assistive technology such as screen readers may have difficulty parsing tables that are so complex that header cells can’t be associated in a strictly horizontal or vertical way. This is typically indicated by the presence of the colspan and rowspan attributes.
Ideally, consider alternate ways to present the table's content, including breaking it apart into a collection of smaller, related tables that don't have to rely on using the colspan and rowspan attributes. In addition to helping people who use assistive technology understand the table's content, this may also benefit people with cognitive concerns who may have difficulty understanding the associations the table layout is describing.
If the table cannot be broken apart, use a combination of the id and headers attributes to programmatically associate each table cell with the header(s) the cell is associated with.
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'table element' in that specification. | Living Standard | |
| HTML5 The definition of 'table element' in that specification. | Recommendation |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | 1 | Yes | 1 | Yes | Yes | Yes |
align
|
1 | Yes | 1 | Yes | Yes | Yes |
bgcolor
|
1 | Yes | 1 | Yes | Yes | Yes |
border
|
1 | Yes | 1 | Yes | Yes | Yes |
cellpadding
|
1 | Yes | 1 | Yes | Yes | Yes |
cellspacing
|
1 | Yes | 1 | Yes | Yes | Yes |
frame
|
1 | Yes | 1 | Yes | Yes | Yes |
rules
|
1 | Yes | 1 | Yes | Yes | Yes |
summary
|
1 | Yes | 1 | Yes | Yes | Yes |
width
|
1 | Yes | 1 | Yes | Yes | Yes |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | 1 | 18 | Yes | 4 | Yes | Yes | Yes |
align
|
1 | 18 | Yes | 4 | Yes | Yes | Yes |
bgcolor
|
1 | 18 | Yes | 4 | Yes | Yes | Yes |
border
|
1 | 18 | Yes | 4 | Yes | Yes | Yes |
cellpadding
|
1 | 18 | Yes | 4 | Yes | Yes | Yes |
cellspacing
|
1 | 18 | Yes | 4 | Yes | Yes | Yes |
frame
|
1 | 18 | Yes | 4 | Yes | Yes | Yes |
rules
|
1 | 18 | Yes | 4 | Yes | Yes | Yes |
summary
|
1 | 18 | Yes | 4 | Yes | Yes | Yes |
width
|
1 | 18 | Yes | 4 | Yes | Yes | Yes |
<caption>, <col>, <colgroup>, <tbody>, <td>, <tfoot>, <th>, <thead>, <tr>;<table> element: width to control the width of the table;border, border-style, border-color, border-width, border-collapse, border-spacing to control the aspect of cell borders, rules and frame;margin and padding to style the individual cell content;text-align and vertical-align to define the alignment of text and cell content.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table