Tables
Data in rows and columns that people compare, scan and sort.
A table is for data that has several attributes per row and that people compare. For a list of one thing per line, use a list group.
When to use it
Use it
- A header row with short column names; numbers aligned to the right.
- Highlight the row under the pointer (
table-hover) when rows are actionable. - Wrap wide tables in
table-responsiveso the page never scrolls sideways. - Keep the actions of a row in the same place and always visible.
Don't
- Use a table for layout.
- Colour rows without a text that says why.
- Hide columns that are needed to understand the row.
Anatomy
A table with a caption, a header (thead, th scope="col") and a body (tbody) whose first cell can be the row header (th scope="row"). Rows and cells can take a contextual colour.
Variants and states
| Assignment | Due | Status | Grade |
|---|---|---|---|
| Essay: climate | 12 Nov | Graded | 8.5 |
| Lab report 2 | 19 Nov | Submitted | — |
| Quiz: equations | 26 Nov | Not started | — |
| Final project | 10 Dec | Not started | — |
This Moodle version has no dark mode: examples stay light.
Toolbar, selection, actions and pager
How Didactika builds a table that people work with: a toolbar over it (search, filters and the main action), a bar that appears when rows are selected, a checkbox column, sortable headers, the actions of a row at the end and always visible, and the pager of a list under it. All of it lives in one card.
| Category | Status | Actions | |||
|---|---|---|---|---|---|
| Algebra I | Mathematics | 128 | Open | ||
| Physics II | Sciences | 94 | Open | ||
| Chemistry lab | Sciences | 71 | Draft | ||
| World history | Humanities | 156 | Closed |
This Moodle version has no dark mode: examples stay light.
Compact, with people and progress
| Participant | Role | Last access | Progress |
|---|---|---|---|
| ALAda Lovelace | Teacher | 2 minutes ago | 100% |
| GHGrace Hopper | Student | Yesterday | 72% |
| ATAlan Turing | Student | 3 days ago | 38% |
This Moodle version has no dark mode: examples stay light.
Sortable headers
A sortable header is a button inside the th. Only one column is sorted at a time, and the aria-sort of its th (ascending, descending or none) says which: there is one arrow: in the sorted column it is solid, in the primary colour, and points up (ascending) or down (descending); in the others it is faint and points down until the pointer or the keyboard reaches them.
| Algebra I | Ana Ruiz | 128 | 74% |
|---|---|---|---|
| Physics II | Luis Gil | 94 | 58% |
| Chemistry lab | Eva Marín | 71 | 91% |
| World history | Marta Soto | 52 | 66% |
This Moodle version has no dark mode: examples stay light.
Row styles
| Striped | Participants |
|---|---|
| Algebra I | 128 |
| Physics II | 94 |
| Chemistry | 71 |
| Bordered, small | Participants |
|---|---|
| Algebra I | 128 |
| Physics II | 94 |
| Row colours | Meaning |
|---|---|
| table-success | Completed |
| table-warning | Needs attention |
| table-danger | Failed |
| table-active | Selected |
This Moodle version has no dark mode: examples stay light.
Combinations
| Combination | Use it for |
|---|---|
| Table × toolbar | Search and filters on the left, the main action on the right; the toolbar sits inside the same card as the table. |
| Table × selection | A checkbox column; when rows are selected a bar shows how many and the actions that apply to them. |
| Table × row actions | Icon buttons at the end of the row (edit, hide, delete), always visible, never hidden until hover. |
| Table × pager | The pager of a list in the foot: rows per page, range and arrows. |
| Table × status | A soft badge with a dot for the state of each row. |
| Compact × people | Small padding, an avatar with a name, a role in a badge and a thin progress bar. |
What Didactika changes and why
| What we changed | Why it helps |
|---|---|
| Full width, a small capital header and quiet lines | The header is a label, not a title; the eye goes to the data. |
| The actions of a row are always visible | Hiding them until hover makes them invisible on touch screens and for keyboard users, and moves the layout. |
| The selected row is tinted | It is clear what an action will apply to before it is pressed. |
| The toolbar, the table and the pager are one card | They are one object; the user sees one thing to work with. |
| Sortable headers are buttons with an icon | They announce the order and are reachable by keyboard. |
Classes
| Class | What it does |
|---|---|
table |
Base |
table-striped, table-hover, table-bordered |
Stripes, row hover and borders |
table-sm |
Compact |
table-active, table-success… |
Colour of a row or cell |
table-responsive |
Scrolls inside its box on small screens |
align-middle |
Vertical alignment |
table-toolbar, table-toolbar-start, table-toolbar-end |
The bar over a table (Didactika) |
table-toolbar-selection |
The bar that appears when rows are selected (Didactika) |
table-select |
The narrow column of the checkbox (Didactika) |
table-actions |
The cell with the actions of a row (Didactika) |
table-sort |
A sortable header (Didactika) |
table-foot |
The foot of a table, for the pager (Didactika) |
In this version
Bootstrap 5.3 keeps its colours in CSS variables (--bs-*), so a theme recolours the component with one variable.
Bootstrap 4.6 compiles its colours into the classes, so a theme recolours the component by rebuilding its stylesheet.
Bootstrap 4.6 compiles its colours into the classes, so a theme recolours the component by rebuilding its stylesheet.
Accessibility
- Use
thwithscope, and acaption(it can be visually hidden). - Do not use a table for layout.
- A coloured row also says it with text.
- Sortable columns announce the order (
aria-sort).
UI