Automatic registration
The captioned table remains readable if JavaScript or the CDN fails; sort buttons appear only after enhancement. At narrow widths, focus the table region and use arrow keys to scroll. Use plain-text headers: enhancement replaces their contents with native buttons.
<script type="module">
import { defineTableSortable } from 'https://unpkg.com/@aarongustafson/table-sortable@latest/define.js?module';
defineTableSortable();
</script>
<table-sortable tabindex="0" role="region" aria-label="People table">
<table>
<caption>People and cities</caption>
<thead>
<tr><th>Name</th><th>Age</th><th>City</th></tr>
</thead>
<tbody>
<tr><td>Charlie</td><td>35</td><td>New York</td></tr>
<tr><td>Alice</td><td>28</td><td>Boston</td></tr>
<tr><td>Bob</td><td>42</td><td>Chicago</td></tr>
</tbody>
</table>
</table-sortable>
| Name | Age | City |
|---|---|---|
| Charlie | 35 | New York |
| Alice | 28 | Boston |
| Bob | 42 | Chicago |