Tables
The HTML <table>
element and related elements, as defined in the HTML specification, can be used to present tabular data. Historically, table markup has been misapplied for page layout purposes, affecting how assistive technologies handle tables.
Recommendations
Mark up data tables in a way that enables browsers and assistive technologies to identify them as such.
Why it matters
Assistive technologies such as screen readers identify tables as being either for data or for layout based on the HTML markup used. If a <table>
with tabular data is poorly marked up and identifies as a layout table, then potentially useful structures for navigating and understanding the content may get ignored.
The following algorithm* is used to determine if a <table>
has been marked up in a way that allows browsers and assistive technologies to identify it as a data table. Go through each check in turn, stopping when you reach a data table or layout table result.
*Algorithm:
- Table inside editable area is data table, always, since the table structure is crucial for table editing.
- Table having ARIA table related
role
is data table (like ARIAgrid
ortreegrid
). - Table having ARIA landmark
role
is data table. - Table having
datatable="0"
attribute is layout table. - Table created by CSS
display
style is layout table. - Table having summary attribute or legitimate data table structures is data table; these structures are:
<caption>
element,<col>
or<colgroup>
elements,<tfoot>
or<thead>
elements,<th>
elements,header
,scrope
orabbr
attributes on table cell,abbr
element as a single child element of table cell.
- Table having nested table is layout table.
- Table having only one row or column is layout table.
- Table having many columns (>= 5) is data table.
- Table having borders around cells is data table.
- Table having differently coloured rows is data table.
- Table having many rows (>= 20) is data table.
- Wide table (more than 95% of the document width) is layout table.
- Table having small amount of cells (<= 10) is layout table.
- Table containing
<embed>
,<object>
,<applet>
of iframe elements (typical advertisements elements) is layout table. - Otherwise it鈥檚 data table.
Examples
Recommended:
<style>
table, th, td {
border: 1px solid black;
}
table {
border-collapse: collapse;
}
</style>
<table>
<caption>Premier League top scorers</caption>
<thead>
<tr>
<th scope="col">Player</th>
<th scope="col">Goals</th>
</tr>
</thead>
<tbody>
<tr>
<td>Vardy</td>
<td>23</td>
</tr>
<tr>
<td>Aubameyang</td>
<td>22</td>
</tr>
<tr>
<td>Ings</td>
<td>22</td>
</tr>
</tbody>
</table>
Not recommended:
<table>
<tr>
<td>Player</td>
<td>Goals</td>
</tr>
<tr>
<td>Vardy</td>
<td>23</td>
</tr>
<tr>
<td>Aubameyang</td>
<td>22</td>
</tr>
<tr>
<td>Ings</td>
<td>22</td>
</tr>
</table>
Testing
Find all <table>
elements in the source code and follow the defined algorithm above to check that each identifies as a data table.