HTML Tables: Find Out When To Use Them (And When To Avoid)

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more

Sharing is caring!

Last Updated on

Tables are used in HTML documents (web pages) to present tabular data.

Using Tables

  • A table is defined using the <table> element, and contains a number of table cells ( <td>, for “table data” ) which are organized into table rows ( <tr>). The markup (HTML code) for a table is always based on rows, never columns.
  • Table cells which act as column headers or row headers should use the <th> (table header) element.
  • Table cells can be merged using the colspan and rowspan attributes.
  • Tables can be broken into sections using the following elements:
  • <thead> — Table header
  • <tbody> — Table body
  • <tfoot> — Table footer
  • A caption can be added to a table using the <caption> element.
  • You can use <col> and <colgroup> to define table columns for styling. However, there are a number of limitations with this practice.
  • Table Code Sample: Simple Table

      <th>Favorite Color</th>
    NameFavorite Color

    Table Code Sample: Complex Table

     <caption>A complex table</caption>
       <th colspan="3">Invoice #123456789</th>
       <th>14 January 2025
       <td colspan="2">
        <strong>Pay to:</strong><br>
        Acme Billing Co.<br>
        123 Main St.<br>
        Cityville, NA 12345
       <td colspan="2">
        John Smith<br>
        321 Willow Way<br>
        Southeast Northwestershire, MA 54321
       <th>Name / Description</th>
       <td>Staples (box)</td>
       <th colspan="3">Subtotal</th>
       <td> 110.00</td>
       <th colspan="2">Tax</th>
       <td> 8% </td>
       <th colspan="3">Grand Total</th>
       <td>$ 118.80</td>
    A complex table
    Invoice #12345678914 January 2025
    Pay to:
    Acme Billing Co.
    123 Main St.
    Cityville, NA 12345
    John Smith
    321 Willow Way
    Southeast Northwestershire, MA 54321
    Name / DescriptionQty.@Cost
    Staples (box)
    Grand Total
    $ 118.80

    About Table-Based Layout

    It was common in the early days of the web to use tables as a layout device. Before the advent of modern standards-based browsers, this was the easiest way to make sure that page elements were arranged properly on the screen.

    This design pattern is now considered very bad. It is bad for the user experience, bad for SEO, and bad for developers who have to maintain pages.

    You should not use table-based layout under any circumstances. Instead, check out our CSS Tutorials to start learning about modern web site layout.

    However, that doesn’t mean you should avoid tables — tables should be used whenever you need to present information in a tabular format.

    Adam is a technical writer who specializes in developer documentation and tutorials.