Chromium now supports sticky table sections

Earlier coverage of sticky table headers and first columns had to work around a browser limitation: position: sticky worked on <thead>, <tfoot>, and <tr> in Safari and Firefox, but not in Chrome. The workaround was to stick individual cells (<th> and <td>) instead. That limitation has been lifted.

I heard through the Twitter that Chrome "rewrote tables" in v91.https://t.co/vTBplXWWtT

I saw it dropped, upgraded, and did a quick test. HEY LOOK STICKY TABLE HEADERS AND FOOTERS.@CodePen https://t.co/8eCP1GMer0

(Works in Safari and Firefox too) pic.twitter.com/rBN3bXm5iD

— Chris Coyier (@chriscoyier) June 4, 2021

According to the reporting, a substantial overhaul of table rendering in Chromium brought tables up to date, and the change covers more than stickiness. The focus here stays on the sticky behavior.

Sticky headers and footers

The most significant result is that <thead> and <tfoot> can now be made sticky, which seems likely to be the most common use case. It works in all three major browsers.

table thead,
table tfoot {
  position: sticky;
}
table thead {
  inset-block-start: 0; /* "top" */
}
table tfoot {
  inset-block-end: 0; /* "bottom" */
}

Conditional approaches, such as enabling stickiness only above a minimum viewport height, are possible, but the core behavior is what matters.

Sticky columns are still cell-based

The <col> element cannot be made sticky. It does not wrap columns; it functions as a pointer for styling down a column, and it is rarely used. Sticky columns remain achievable by selecting every cell in the column and sticking it to the left or right — shown here with logical properties.

table tr th:first-child {
  position: sticky;
  inset-inline-start: 0; /* "left" */
}

A deliberately obnoxious demonstration combines a sticky <thead>, a sticky <tfoot>, and sticky first and last columns. With more restraint, the technique can be applied tastefully.

A `sticky` table row/column can be such a nice touch. Here's an example from @destroytoday https://t.co/uN3nIisHxF pic.twitter.com/KttE5puBqZ

— Chris Coyier (@chriscoyier) June 2, 2021