Lesson 6 of 8
Responsive Table Patterns
Tables can be problematic on small screens - a 6-column table doesn't fit on a phone. There are several proven responsive patterns: horizontal scroll wrappers, stacked card layouts, and hiding non-essential columns. Knowing these patterns is essential for real-world projects.
Responsive Strategies
- Horizontal scroll wrapper - Wrap table in <div style="overflow-x: auto">. The simplest approach - users can scroll horizontally. Best for data tables where all columns are important.
- Stacked card layout - On mobile, use CSS to display each row as a card. Each <td> becomes a block element with the column header shown via a data-label attribute and CSS ::before pseudo-element.
- Hide non-essential columns - Use media queries to hide less important columns on small screens. Show a 'View full table' link for users who need all data.
- Priority columns - Mark columns as high/medium/low priority. Show all on desktop, hide low-priority on tablet, hide medium too on phone.
- Sticky first column - Keep the row headers visible while scrolling horizontally. Use position: sticky and left: 0 on the first column.
Responsive Table Example
Responsive Table Example
<!DOCTYPE html>
<html>
<head>
<style>
.table-wrapper { overflow-x:auto; border-radius:8px; box-shadow:0 2px 8px rgba(0,0,0,0.1); }
table { width:100%; border-collapse:collapse; min-width:500px; }
th, td { padding:12px 16px; text-align:left; border-bottom:1px solid #eee; }
th { background:#2c3e50; color:white; position:sticky; top:0; }
tr:hover { background:#f5f5f5; }
tr:nth-child(even) { background:#fafafa; }
</style>
</head>
<body>
<h2>Responsive Table (scroll on mobile)</h2>
<div class="table-wrapper">
<table>
<thead>
<tr><th>Name</th><th>Role</th><th>Email</th><th>Salary</th><th>Location</th></tr>
</thead>
<tbody>
<tr><td>Alice</td><td>Developer</td><td>alice@co.com</td><td>$95,000</td><td>New York</td></tr>
<tr><td>Bob</td><td>Designer</td><td>bob@co.com</td><td>$85,000</td><td>London</td></tr>
<tr><td>Charlie</td><td>Manager</td><td>charlie@co.com</td><td>$110,000</td><td>Mumbai</td></tr>
</tbody>
</table>
</div>
<p style="color:#999;font-size:13px">↔ Scroll horizontally on small screens</p>
</body>
</html>Diagram
Loading diagram…
Use scroll containers or CSS stacked cards to display wide tables on phones
Key Takeaways
- Tables can be problematic on small screens - a 6-column table doesn't fit on a phone.
- Horizontal scroll wrapper - Wrap table in <div style="overflow-x: auto">. The simplest approach - users can scroll horizontally. Best for data tables where all columns are important.
- Stacked card layout - On mobile, use CSS to display each row as a card. Each <td> becomes a block element with the column header shown via a data-label attribute and CSS ::before pseudo-element.
- Hide non-essential columns - Use media queries to hide less important columns on small screens. Show a 'View full table' link for users who need all data.
Finished this lesson?
0 of 8 in Module 5