Table Responsive Examples
Responsive table layouts that adapt to narrow viewports using container queries and card-based layouts.
Responsive Card Layout
When the table container is narrower than 500px, each row transforms into a card with labeled fields. Uses data-responsive="card" on the table and data-label on each cell.
| Name | Role | Status | |
|---|---|---|---|
| Alice Chen | alice.chen@company.com | Senior Engineer | Active |
| Bob Martinez | bob.martinez@company.com | Marketing Lead | Active |
| Carol Johnson | carol.johnson@company.com | Sales Manager | On Leave |
| David Kim | david.kim@company.com | Developer | Active |
| Emma Wilson | emma.wilson@company.com | UX Designer | Active |
Card Layout Preview
This container is constrained to 400px width to demonstrate the card layout without resizing.
Container width: 400px
| Product | Price | Stock |
|---|---|---|
| Wireless Keyboard | $79.99 | 42 units |
| USB-C Hub | $49.99 | 128 units |
| Monitor Stand | $119.99 | 15 units |
| Webcam HD | $89.99 | 67 units |
How It Works
HTML Structure
Add data-responsive="card" to the table and data-label to each <td>:
<table-wc>
<table data-responsive="card">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Name">Alice Chen</td>
<td data-label="Email">alice@example.com</td>
</tr>
</tbody>
</table>
</table-wc>
Container Query Behavior
The table-wc element uses container-type: inline-size to enable container queries. When the container is narrower than 500px:
- The table header is hidden
- Each row becomes a bordered card
- Each cell displays as a grid with the
data-labelvalue on the left
Benefits
- Progressive Enhancement
- Tables remain fully functional without JavaScript. The responsive behavior is pure CSS.
- Container-Based
- Responds to the container width, not viewport. Works in sidebars, modals, and constrained layouts.
- Accessible
- Screen readers still receive the full table semantics. Labels provide context for each value.