Sticky headers can help users keep column meaning visible while scrolling long tables. Use position: sticky carefully with a background color and z-index so text does not overlap.
Tables often show status such as paid, failed, pending, or active. Use text labels plus color, not color alone, so the meaning remains clear for all users.
Numbers and dates need alignment. Right-align numbers for comparison, use tabular numerals, and keep date formats consistent across the column.
<div class="table-wrap">
<table class="report-table">
<caption>Monthly sales report</caption>
<thead>
<tr>
<th scope="col">Month</th>
<th scope="col">Orders</th>
<th scope="col">Revenue</th>
</tr>
</thead>
<tbody>
<tr><td>January</td><td>328</td><td>$24,600</td></tr>
<tr><td>February</td><td>415</td><td>$31,900</td></tr>
</tbody>
</table>
</div>
.table-wrap {
max-width: 100%;
overflow-x: auto;
}
.report-table {
width: 100%;
min-width: 680px;
border-collapse: collapse;
}
.report-table th,
.report-table td {
border: 1px solid #dbe3ef;
padding: 12px 14px;
}
.report-table tbody tr:nth-child(even) {
background: #f8fafc;
}
.report-table td:nth-child(2),
.report-table td:nth-child(3) {
text-align: right;
font-variant-numeric: tabular-nums;
}
.report-table thead th {
position: sticky;
top: 0;
z-index: 2;
background: #0f172a;
color: white;
}
.table-scroll {
max-height: 420px;
overflow: auto;
}
<td>
<span class="status status-paid">Paid</span>
</td>
<style>
.status {
border-radius: 999px;
padding: 0.25rem 0.6rem;
font-weight: 700;
}
.status-paid {
background: #dcfce7;
color: #166534;
}
</style>
It merges adjacent cell borders so the table does not show doubled lines.
Place it in a horizontally scrollable wrapper instead of squeezing every column until the text is unreadable.
No. Use th elements with the correct scope so assistive technology understands the relationships.
Practice, interview questions, and compiler links for CSS.
Finish the concept here, then reinforce it with hands-on coding, interview prep, or a tool that matches the topic.
Explore 500+ free tutorials across 20+ languages and frameworks.
Fresh tutorials, interview guides, and coding practice in your inbox.