HTML - <table>
The HTML Table Element (<table>
) represents tabular data - i.e., information expressed via a two dimensional data table.
Examples
Simple Table
HTML
Copy Code
<table> <tr> <td>John</td> <td>Doe</td> </tr> <tr> <td>Jane</td> <td>Doe</td> </tr> </table>
More Examples
HTML
Copy Code
<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> <tfoot> <tr> <td>Footer content 1</td> <td>Footer content 2</td> </tr> </tfoot> <tbody> <tr> <td>Body content 1</td> <td>Body content 2</td> </tr> </tbody> </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>
CSS
Copy Code
table { border-collapse: collapse; border-spacing: 0px; } table, th, td { padding: 5px; border: 1px solid black; }
Description
The HTML Table Element (<table>
) represents tabular data - i.e., information expressed via a two dimensional data table.
Note: Prior to the creation of CSS, HTML
<table>
elements were often used as a method for page layout. This usage has been discouraged since HTML 4. However, HTML emails are an exception where tables are still commonly used for layout purposes. The reason for this is poor CSS support in popular email clients.Content categories | Flow content |
Permitted content | |
Tag omission | None, both start and end tag are mandatory |
Permitted parent elements | Any element that accepts flow content |
Normative document | HTML5, section 4.9.1 (HTML4.01, section 11.2.1) |
Browser Compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | 4.0[1] | 7.0 | 1.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1) | 6.0[1] | 6.0 | 1.0 |
[1] There is an Internet Explorer 9 rendering bug involving <table>
and :hover
; see the "Browser compatibility" section of the :hover
article for details.
See Also
- Other table-related HTML Elements:
<caption>
,<col>
,<colgroup>
,<tbody>
,<td>
,<tfoot>
,<th>
,<thead>
,<tr>
; - CSS properties that may be esspecially useful to style the
<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
andpadding
to style the individual cell content;text-align
andvertical-align
to define the alignment of text and cell content.
This element implements the HTMLTableElement
interface.
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/html/element/table