Skip to content

Responsive Table that Stacks on Mobile

Pure CSS invoice table that turns every row into a labeled card on narrow screens using a container query and data-label attributes.

Also known as: responsive data table, table to cards mobile, stacking table on mobile, mobile friendly table, invoice table responsive

Responsive Table that Stacks on Mobile live demo

Open in new tab

Pure CSS code (HTML, CSS)

A responsive data table that changes layout on small screens: each row becomes a card, and every value gets its column name as a label. It is pure CSS with no JavaScript, and it suits invoices, orders, user lists and other admin tables that need to stay readable on phones without horizontal scrolling.

How it works

The .st-card wrapper is a size container (container-type: inline-size, named st), so the table reacts to the width of its card instead of the viewport. That means it also stacks inside a narrow sidebar or dashboard column on a large screen.

The default styles are the mobile layout. The .st-table, its tbody, rows and cells are set to block or flex display. The thead is hidden visually but kept for screen readers. Each td has a data-label attribute, and td::before prints it with content: attr(data-label), so a cell reads as "AMOUNT ... $4,250.00". Rows get a rounded border and a colored left edge, and cells are separated by dashed lines.

When the card is at least 44rem wide, the @container st (min-width: 44rem) block switches everything back to table, table-row-group, table-row and table-cell, shows the header row and removes the generated labels. Numeric columns use .st-num for right alignment and tabular figures.

Customization

  • data-label on each td: the label shown on mobile. Keep it in sync with the matching th text.
  • 44rem in the @container rule: the width at which the table layout returns. Raise it for tables with more columns.
  • --st-accent on .st-wrap: the color of the row edge on mobile, the links and the focus outline.
  • --st-label-width: the width of the label column in the stacked cards.
  • .st-pill--paid, .st-pill--pending, .st-pill--overdue and .st-pill--draft: status badge colors. Add a new modifier for other states.
  • .st-avatar--1 to .st-avatar--4: background and text colors of the client initials.

Use cases

  • Billing pages: invoice rows become labeled cards on narrow screens
  • Admin dashboards: data stays readable on phones without horizontal scrolling
  • Customer portals: data-label attributes name every value in the stacked layout
  • Reports: a container query switches layouts based on the available width

Accessibility

Changing display on table elements can remove table semantics in some browsers, so the markup sets them explicitly with role="table", rowgroup, row, columnheader and cell. The table is labelled by its heading through aria-labelledby. Each View link includes hidden text such as "invoice 2041" so it is unique out of context, and links get a visible focus outline. Status colors also carry a text label, so color is never the only signal.

Usage notes

Container queries are supported in all current browsers. In very old browsers the table stays in its stacked card layout, which still works at any width.

Responsive Table that Stacks on Mobile at a glance

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

Questions about this template

Can I use the Responsive Table that Stacks on Mobile 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.

Responsive Table that Stacks on Mobile – free Pure CSS table template
Responsive Table that Stacks on Mobile · 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.

Invoice Table – free Bootstrap 6 table template

Invoice Table

Bootstrap 6 invoice table on a paper-style sheet with editable quantities, taxable and exempt line items, a discount, a selectable tax rate and live totals.

Users Table with Avatars – free Bootstrap 6 table template

Users Table with Avatars

Dark Bootstrap 6 team members table with photo avatars, presence dots, role badges, status, search, role filter and per-row action menus that stacks into cards on mobile.

Table with Checkbox Selection – free Bootstrap 6 table template

Table with Checkbox Selection

Bootstrap 6 orders table with row checkboxes, an indeterminate select-all box, Shift-click ranges and a bulk actions bar with export menu, delete and undo.

Striped and Hover Table Styles – free Bootstrap 6 table template

Striped and Hover Table Styles

Interactive Bootstrap 6 table style playground: toggle striped, hover, bordered, small and dark variants and copy the resulting table markup.