Back to CSS Notes
Topic #227

Responsive Tables

You will make a wide data table usable on small screens by wrapping it in a scrollable container and giving the table a minimum width so columns stay readable.

What it is

A responsive table is a table that remains usable when the viewport is narrower than the table’s natural width. Instead of forcing every column to fit, you let the table scroll horizontally, or you change its layout for small screens. The most common pattern is a wrapper element with overflow-x: auto around the table. Related terms include min-width, sticky headers, overflow, and stacked or card-style tables.

Why it matters

  • It prevents long text from being clipped or squeezed into unreadable columns.
  • It keeps rows and columns aligned, which is important for comparing data.
  • It works well with touch and keyboard scrolling on phones and tablets.
  • It avoids the need to shrink font size until the table becomes inaccessible.

Syntax or steps

  1. Wrap the table in a container element.
  2. Set the container to scroll horizontally when needed.
  3. Give the table a minimum width so columns do not collapse.
  4. Optionally make the header or first column sticky so labels stay visible.

Example

<div class="table-wrap">
  <table>
    <thead>
      <tr>
        <th>Product</th>
        <th>SKU</th>
        <th>Price</th>
        <th>Stock</th>
        <th>Supplier</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Wireless Mouse</td>
        <td>WM-100</td>
        <td>$24.99</td>
        <td>142</td>
        <td>TechSupply</td>
      </tr>
    </tbody>
  </table>
</div>
.table-wrap {
  overflow-x: auto;
}

.table-wrap table {
  min-width: 640px;
  border-collapse: collapse;
}

th,
td {
  padding: 0.5rem;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

thead th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
}

thead th:first-child {
  z-index: 3;
}

Part by part:

  • The .table-wrap element is the scroll container. The table itself stays inside it.
  • overflow-x: auto adds a horizontal scrollbar only when the table is wider than the container.
  • min-width: 640px keeps the columns from becoming too narrow on small screens.
  • position: sticky on thead th keeps column headings visible while scrolling vertically.
  • Sticky first column keeps row labels visible while scrolling horizontally.

Common mistakes

  • Applying overflow-x directly to the table. Use a wrapper so the table can keep its normal table layout.
  • Forgetting min-width. Without it, columns may squeeze and text may wrap badly.
  • Using overflow: hidden. This can hide data instead of letting users scroll to it.
  • Using sticky cells without a background. Scrolled content can show through the sticky cells.

When to use it

Use a scrollable wrapper when the table has many columns and users need to compare values across rows. Use a stacked or card layout when the table has only a few columns and mobile users mainly read one row at a time.

ApproachBest forTrade-off
Scrollable wrapperWide tables with many columnsRequires horizontal scrolling
Stacked cardsShort tables read row by rowColumn alignment is lost

Practice

Guided exercise: take a table with five columns and wrap it in a container with overflow-x: auto. Add min-width: 600px to the table. Expected result: on a narrow viewport, the table scrolls horizontally instead of breaking the page layout.

Challenge: make the first column sticky while scrolling horizontally. Hint: use position: sticky, left: 0, and a solid background on the first cell in each row.

Quick check

Question: Why is a wrapper usually better than putting overflow-x: auto directly on the table?

Answer: The wrapper creates a predictable scroll container while the table keeps its normal table layout and column sizing.

Summary

Responsive tables are about preserving access to data when space is limited. A simple wrapper with horizontal scrolling and a minimum table width is often the most reliable first solution. Add sticky headers or columns only when they improve orientation without hiding content.

Want to go beyond the notes?

Join Coding Now Tech Institute's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Responsive Tables – FAQs

Quick answers about learning Responsive Tables in CSS.

This free note from Coding Now Tech Institute explains Responsive Tables in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on Coding Now Tech Institute, including Responsive Tables, is 100% free with no signup required.
With focused practice, most students grasp Responsive Tables in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now