Tables

HTML <table> element

Represents two-dimensional tabular data. Use headers and captions to communicate relationships; do not use tables for general page layout. Use a table for genuinely tabular relationships, not page layout. Provide a caption where helpful and use th with appropriate scope or explicit header associations. Check keyboard access and horizontal overflow on smaller screens. It accepts global HTML attributes; individual global features may be inapplicable or restricted.

Formal Syntax & Structure

html syntaxhtml
<table>  <tr>    <td>Data</td>  </tr></table>

Return Value

HTMLTableElement

Content model: Optional caption, optional colgroup elements, optional thead, then tbody groups or tr rows, optional tfoot; script-supporting elements may be interspersed.

Working Example

Example Snippethtml
<!doctype html><html lang="en">  <head>    <meta charset="utf-8">    <title>HTML example</title>  </head>  <body>    <table>      <caption>Stock</caption>      <tr>        <th scope="col">Item</th>        <th scope="col">Count</th>      </tr>      <tr>        <td>Books</td>        <td>2</td>      </tr>    </table>  </body></html>
HTML Reference