Skip to content

Table with Sticky Header

Dark striped data table in pure CSS with a sticky header row and sticky first column inside a scrollable, keyboard-focusable container.

Also known as: fixed header table, sticky column table, scrollable data table, table with frozen header

Pure CSS Tables Responsive Dark #dark #responsive #sticky #striped #table

Table with Sticky Header live demo

Open in new tab

Pure CSS code (HTML, CSS)

A dark, striped data table in pure CSS with a sticky header row and a sticky first column, so labels stay visible while you scroll through wide and long data. It works well for reports, financial dashboards, pricing matrices and any spreadsheet-like view on the web, with no JavaScript.

How it works

The root section.tsh-wrap contains a .tsh-top header (title, subtitle and a small legend) and a .tsh-scroll container. The container has a max-height and overflow: auto, which turns it into the scroll box that sticky positioning works against. Inside sits table.tsh-table with a visually hidden .tsh-caption, a thead of month columns and a tbody where every row starts with a th scope="row" region name.

Three rules do the sticky work. thead th gets position: sticky; top: 0, so the header stays at the top of the box. tbody th gets position: sticky; left: 0, so region names stay on the left during horizontal scrolling. The corner cell, thead th:first-child, is sticky on both axes and has the highest z-index, so it always sits above the other sticky cells. The table uses border-collapse: separate because collapsed borders do not move with sticky cells, and every cell has an opaque background so scrolled content never shows through.

Zebra stripes come from tbody tr:nth-child(even) > *, which also colors the sticky row headers. Hovering a row highlights it, the .tsh-total column is drawn in the accent color, and .tsh-peak marks the best month of each region with a dot.

Customization

  • --tsh-height on .tsh-wrap: maximum height of the scroll area; raise it to show more rows before vertical scrolling starts.
  • --tsh-first-col: minimum width of the sticky region column.
  • min-width on .tsh-table: when horizontal scrolling begins; lower it for tables with fewer columns.
  • --tsh-surface, --tsh-stripe and --tsh-head-bg: base row, striped row and header backgrounds.
  • --tsh-accent: underline of the header row, the total column and the focus ring.
  • --tsh-peak: color of the highlighted .tsh-peak cells and the legend swatch; remove the class to drop the highlight.
  • --tsh-radius: corner radius of the scroll container.

Use cases

  • Reports: a sticky header row keeps column names visible while scrolling long data
  • Financial dashboards: a sticky first column keeps row labels in view across wide tables
  • Pricing matrices: striped rows make wide comparisons easier to read
  • Spreadsheet-like views: a keyboard-focusable scroll container lets everyone move through the data

Accessibility

The scroll container has role="region", aria-labelledby pointing to the title and tabindex="0", so keyboard users can focus it and scroll with the arrow keys; a cyan outline shows the focus. Column headers use scope="col" and region names use scope="row", so screen readers announce the correct month and region for every value. The caption describes the table and units for assistive technology. Peak values are not marked by color alone: each one contains a visually hidden .tsh-sr text, "(best month)". Text colors keep strong contrast against the dark backgrounds.

Usage notes

Do not set overflow on any element between the cells and .tsh-scroll, or the sticky cells lose their scroll reference. To add a sticky footer, apply position: sticky; bottom: 0 to tfoot cells in the same way.

Table with Sticky Header at a glance

Framework
Pure CSS
Code
HTML, CSS
JavaScript
Not needed, CSS only
Dependencies
None
Layout
Responsive, works on mobile, dark design
Category
Tables
License
Free for personal and commercial use

Questions about this template

Can I use the Table with Sticky Header code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear and add the CSS to your stylesheet. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. It is built with HTML and CSS only, so there is no JavaScript to load.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Table with Sticky Header – free Pure CSS table template
Table with Sticky Header · free Pure CSS table template

More Tables

Table with Search Filter – free Bootstrap 5 table template

Table with Search Filter

Bootstrap 5 team directory table with live search, status filter, highlighted matches, result counter and empty state.

Sortable Data Table – free Tailwind CSS table template

Sortable Data Table

Tailwind CSS data table with clickable column headers that sort text, dates and numbers, with aria-sort, arrow indicators and a responsive scroll wrapper.

Editable Table with Inline Editing – free Bootstrap 5 table template

Editable Table with Inline Editing

Dark Bootstrap 5 inventory table with click-to-edit cells, validation, live totals, an unsaved changes counter and simulated save and discard.

Product Comparison Table Section for Shopify – free Shopify table template

Product Comparison Table Section for Shopify

Shopify section with a real comparison table for 2 to 4 products: live prices, yes/no icons, row values set in the theme editor, and a sticky first column when it scrolls on phones.

Responsive Table with Actions – free Bootstrap 5 table template

Responsive Table with Actions

Responsive Bootstrap 5 invoice table with status badges, a status filter and row action dropdowns to mark as paid, remind or delete.