Skip to content
IndexRequest a UIAboutContact

Responsive Table to Cards

A data table that reflows into stacked cards when its container gets narrow, using data-label headings.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Clean UI mockup showing the same order list twice: on the left a wide table with columns Order, Customer, Status and Total, on the right a narrow phone-width version where each row has become a stacked card with small grey labels Customer, Status and Total beside the values and the order number in bold on top, thin dividers, light theme, flat modern style. Negative: gradients, shadows, clutter, text errors, device frames. Reduced motion: static design.

About this pattern

Definition

Wide tables are unreadable on a phone. Instead of scrolling sideways, each row can turn into a small card where every cell shows its column name next to its value. A container query makes the switch depend on the space the table actually has, not on the window width.

Purpose & UX principles

  • Keep real table markup; only change display with CSS so semantics stay for large screens.
  • Hide the header row visually and print each cell's column name with a data-label attribute in a ::before.
  • Switch at the width where columns start to squeeze, usually 480 to 600 px.
  • Put the most important cell first in the card and make it bold.

Interaction states

  • A width slider changes the container; below about 340px the rows become cards.

Motion specification

  • The layout switches instantly.
  • Reduced motion: no animation is involved.

Responsive behaviour

  • When the table becomes cards, keep table roles with role attributes or accept the list semantics.
  • Very wide data tables with many columns may still need horizontal scroll.

Code

HTML
<div class="bx"><div class="fw" id="fw"><table class="rt"><thead><tr><th>Order</th><th>Customer</th><th>Status</th><th>Total</th></tr></thead><tbody><tr><td data-label="Order">#1042</td><td data-label="Customer">Ada Lopez</td><td data-label="Status">Shipped</td><td data-label="Total">$128.00</td></tr><tr><td data-label="Order">#1043</td><td data-label="Customer">Ben Okoye</td><td data-label="Status">Packing</td><td data-label="Total">$54.90</td></tr></tbody></table></div><label class="rw">Width <b id="wv">400px</b><input id="ws" type="range" min="220" max="400" value="400"></label><p class="out" id="out"></p></div>

Related patterns

Sticky Table Header & Column

↗
Sticky Table Header & ColumnLayout & Scrolling

Container Query Cards

↗
Container Query CardsLayout & Scrolling

Holy Grail Three-column Layout

↗
Holy Grail Three-column LayoutLayout Structures