Table
Headers
Use table headers to tell users what the rows and columns represent. Use the scope attribute to help users of assistive technology distinguish between row and column headers. How tables work
Accessibility
Follow WebAIM's guidance for tables and
- give tables captions
- use the scope attribute to associate the data cells with the appropriate headers
- let the browser window determine the width of the table whenever possible, to reduce horizontal scrolling
Captions
Use the <caption>
element to describe a table in the same way you would
use a heading. A caption helps users find, navigate and understand tables.
Responsive design
Tables too wide to display in full display with a scroll bar. This can be seen in the scoped column and row variation.
When to use this component
Use the table component to let users compare information in rows and columns.
When not to use this component
Never use the table component to layout content on a page. Instead, use the grid system.
Variations
A minimal table, with a caption
open this example in its own window
Name | Age |
---|---|
Jane Doe | 1 |
Janet Doughnut | 3 |
John Doe | 3 |
Jeff Donut | 7 |
A table with a scoped column and row headers
open this example in its own window
Name | Age | Birth Day | Birth Month | Siblings | Cousins | Colour | Shape | Animal | Hair |
---|---|---|---|---|---|---|---|---|---|
Jane Doe | 1 | 13 | June | 2 | 4 | Blue | Square | Cat | Blonde |
Janet Doughnut | 3 | 23 | October | 0 | 1 | Green | Triangle | Fish | Red |
John Doe | 3 | 5 | January | 1 | 12 | Yellow | Circle | Bird | Brown |
Jeff Donut | 7 | 15 | May | 3 | 6 | Purple | Rectangle | Tortoise | Black |
<div class="table-responsive">
<table class="table">
<caption>
Some people in a table
</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
<th scope="col">Birth Day</th>
<th scope="col">Birth Month</th>
<th scope="col">Siblings</th>
<th scope="col">Cousins</th>
<th scope="col">Colour</th>
<th scope="col">Shape</th>
<th scope="col">Animal</th>
<th scope="col">Hair</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Jane Doe</th>
<td>1</td>
<td>13</td>
<td>June</td>
<td>2</td>
<td>4</td>
<td>Blue</td>
<td>Square</td>
<td>Cat</td>
<td>Blonde</td>
</tr>
<tr>
<th scope="row">Janet Doughnut</th>
<td>3</td>
<td>23</td>
<td>October</td>
<td>0</td>
<td>1</td>
<td>Green</td>
<td>Triangle</td>
<td>Fish</td>
<td>Red</td>
</tr>
<tr>
<th scope="row">John Doe</th>
<td>3</td>
<td>5</td>
<td>January</td>
<td>1</td>
<td>12</td>
<td>Yellow</td>
<td>Circle</td>
<td>Bird</td>
<td>Brown</td>
</tr>
<tr>
<th scope="row">Jeff Donut</th>
<td>7</td>
<td>15</td>
<td>May</td>
<td>3</td>
<td>6</td>
<td>Purple</td>
<td>Rectangle</td>
<td>Tortoise</td>
<td>Black</td>
</tr>
</tbody>
</table>
</div>
Options to the table()
macro
Options to Cell
Options to Row
Options to HeadRow
{% from 'macros/component/table.html' import table %}
{{ table({
'caption': 'Some people in a table',
'head': [
[
{
'body': 'Name',
'headerScope': 'col'
},
{
'body': 'Age',
'headerScope': 'col'
},
{
'body': 'Birth Day',
'headerScope': 'col'
},
{
'body': 'Birth Month',
'headerScope': 'col'
},
{
'body': 'Siblings',
'headerScope': 'col'
},
{
'body': 'Cousins',
'headerScope': 'col'
},
{
'body': 'Colour',
'headerScope': 'col'
},
{
'body': 'Shape',
'headerScope': 'col'
},
{
'body': 'Animal',
'headerScope': 'col'
},
{
'body': 'Hair',
'headerScope': 'col'
}
]
],
'body': [
[
{
'body': 'Jane Doe',
'headerScope': 'row'
},
'1',
'13',
'June',
'2',
'4',
'Blue',
'Square',
'Cat',
'Blonde'
],
[
{
'body': 'Janet Doughnut',
'headerScope': 'row'
},
'3',
'23',
'October',
'0',
'1',
'Green',
'Triangle',
'Fish',
'Red'
],
[
{
'body': 'John Doe',
'headerScope': 'row'
},
'3',
'5',
'January',
'1',
'12',
'Yellow',
'Circle',
'Bird',
'Brown'
],
[
{
'body': 'Jeff Donut',
'headerScope': 'row'
},
'7',
'15',
'May',
'3',
'6',
'Purple',
'Rectangle',
'Tortoise',
'Black'
]
]
}) }}