Skip to content

Semantically correct table

Inju Michorius edited this page Apr 28, 2021 · 4 revisions

A semantically correct table is important for the use of screen readers. A semantically correct table looks like this:

<table>
    <caption>Things to eat</caption>
    <thead>
        <tr>
            <th>Product</th>
            <th>Price</th>
            <th>Vegan</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th>Peach</th>
            <td>1.99 €</td>
            <td>yes</td>
        </tr>
        <tr>
            <th>Cucumber</th>
            <td>0.99 €</td>
            <td>yes</td>
        </tr>
        <tr>
            <th>Cheeseburger</th>
            <td>7.99 €</td>
            <td>no</td>
        </tr>
    </tbody>
</table>

The <caption> tag is important for a screen reader. This makes a screen reader say the following: "Things to eat 3 columns, 5 rows". Furthermore, it is important to neatly divide your table into a ,

and possibly .

A graph that has been placed in html via an image can best be explained with the alt text. This allows a screen reader to explain what it says. However, this requires an extensive explanation of the image.

Sources

Clone this wiki locally