NelsonLabs

Tables

Tables are for tabular data โ€” information that belongs in rows and columns. They're commonly misused for layout (don't do that โ€” that's what CSS Grid and Flexbox are for).

A complete, correct HTML table
html
<table>
  <thead>
    <tr>
      <th>Language</th>
      <th>Type</th>
      <th>Used for</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>JavaScript</td>
      <td>Frontend + Backend</td>
      <td>Interactivity, servers, APIs</td>
    </tr>
    <tr>
      <td>Python</td>
      <td>Backend</td>
      <td>Scripting, AI, web apps</td>
    </tr>
    <tr>
      <td>HTML</td>
      <td>Markup</td>
      <td>Page structure</td>
    </tr>
  </tbody>
</table>

Key table elements

  • โ€”<table> โ€” the container for the entire table
  • โ€”<thead> โ€” groups the header rows (optional but good practice)
  • โ€”<tbody> โ€” groups the data rows
  • โ€”<tr> โ€” table row (contains cells)
  • โ€”<th> โ€” table header cell (bold, centred by default)
  • โ€”<td> โ€” table data cell (regular content)
Spanning multiple columns or rows
html
<table>
  <tr>
    <td colspan="2">This cell spans 2 columns</td>
    <td>Normal cell</td>
  </tr>
  <tr>
    <td rowspan="2">This cell spans 2 rows</td>
    <td>Cell 2</td>
    <td>Cell 3</td>
  </tr>
  <tr>
    <td>Cell 4</td>
    <td>Cell 5</td>
  </tr>
</table>

WARNING

Tables are NOT for layout. Before CSS was widely supported, developers used tables to create page layouts (columns, grids, etc.). That technique is completely obsolete. Never use tables for layout โ€” only use them for actual tabular data like schedules, comparison charts, and pricing tables.