Skip to content
Leonidov.DEV

Progressive Enhancement: One Table, Three Layers

Engineering
Progressive Enhancement: One Table, Three Layers

Progressive enhancement gets taught as a slogan and practised as a fallback nobody tests. On a sortable table the idea becomes concrete: one piece of markup, three layers of behaviour, and a rule about what each layer may assume.

Code: Oat-Table, MIT licensed.

Layer one: the document

Markup first, and not as a placeholder. A <table> with <thead>, <tbody> and <th scope="col"> is already sortable by hand, printable, searchable with find-in-page, and readable by a screen reader that knows what a column is.

This layer is the contract. Everything above it may be lost and the page still has to make sense.

Layer two: the styles

CSS carries the visual state: a sorted column, a hidden row, a hover on a clickable header. Nothing in this layer may hide information that only exists if the stylesheet loads.

The trap here is the empty state. If a filter hides every row, the user needs a sentence, and that sentence belongs in the markup as an attribute, not in a JavaScript string.

Layer three: the behaviour

The script wraps the header text in a <button>, maintains aria-sort, filters rows on input, and keeps selection state on the elements that own it: the checkboxes. No parallel data model, no re-render.

The rule for this layer: it may add, and it may not be required. If the bundle fails, the table renders as layer one, which is a degraded feature and not a broken page.

Why the order matters

Most implementations are built backwards: a data array, a render function, then markup generated from it. That order makes the document optional, and once the document is optional, the accessible version is a second implementation that nobody has time to maintain.

Building from the markup down means the accessible version is the first version, and the enhanced one reuses it.

Three tests that catch the regressions

Disable JavaScript and load the page. If content disappeared, layer one was a placeholder.

Block the stylesheet. If the sort state vanished into ambiguity, layer two was carrying meaning it should not carry.

Tab through the headers and the checkboxes. If focus lands on a th or a td, layer three forgot the button.

The budget for the third layer

Set it before writing the script: a size in kilobytes, a time to interactive on a mid-range phone, and the number of files the browser must fetch before the table sorts. A third layer without a budget grows until it is the product.

The same numbers tell you when to move to a server-rendered page or a library. A table that needs sorting on ten thousand rows is not a table any more, and the honest response is a different architecture rather than a bigger bundle.

Where this pattern fails

It fails on data that does not exist in the document: a search over ten thousand records, a live feed, an editor. There the server has to render a page that explains itself, and the interaction genuinely needs JavaScript.

It also fails when the team treats “works without JS” as a checkbox and stops testing after sprint one. The fallback survives on discipline, not on intent.

What I ask for in review

Show me the page with scripts blocked. Show me the sorted state as a screen reader announces it. Show me the payload of the form after filtering and selecting all.

Three demonstrations, five minutes, and they decide whether the feature is progressive enhancement or decoration.

I use the same test order when reviewing content: the structure first, then the styling, then the interactive part, as in ten content angles and three checks. A page that only works at the last layer is fragile in the same way.

Background: Oat Table on GitHub and the Oat UI documentation, MIT licensed.