About this set
A team table whose four column headers sort the rows: name, role, commit count and last active time. Click a header to sort ascending, click it again to reverse, and the other headers return to a neutral state with two grey arrows. Each header cell holds a real button, so sorting works with a mouse, with Tab and Enter or Space, and with a screen reader. The script writes aria-sort as ascending or descending on the active header cell, and the CSS colours the arrows and the header text from that attribute, so what is shown and what is announced cannot drift apart. Values are compared in three ways: a time element is sorted by its datetime attribute, cells that hold a number are compared as numbers with thousands separators removed, and everything else is compared as lowercase text. That keeps 1,284 above 942 and puts 2 hours ago before Yesterday. Use it for any small to medium table that is sorted in the browser; for server-side sorting, keep the markup and aria-sort and replace the array sort with a request. The Bootstrap version is a .table-hover inside a .card and .table-responsive, and the Tailwind version uses group-aria-[sort] variants for the arrows.
What’s included
- Three header states: none, ascending and descending
- aria-sort on the active header drives the arrow styling
- Sorts dates by datetime, numbers numerically and text alphabetically
- Header buttons work with the keyboard and show a focus ring
- Scrolls sideways in a labelled, focusable region on narrow screens
Accessibility
The table has a caption, every header is a th with scope="col" and holds a native button, and the active header carries aria-sort. The arrows are aria-hidden because the sort direction is exposed through aria-sort. Header buttons and the scroll region show a 2px indigo outline on keyboard focus. Nothing animates.
Customise it
Change the indigo #4f46e5 used for the active header and arrows and the #c5cbd6 idle arrow colour in the .arrows rules (plain CSS and Bootstrap) or in the group-aria-[sort] classes (Tailwind). Row padding sits on .tbl td, on .tbl > :not(caption) > * > * in Bootstrap, and in the [&_td] utilities in Tailwind.




















