Creating Responsive HTML Tables

Wide HTML tables can extend beyond the viewport on phones and other small screens, making part of the data difficult or impossible to reach.

A common responsive solution is to preserve the table's semantic structure and place it inside a container that allows horizontal scrolling when the table is wider than the available space.

The Responsive Table Problem

Tables are designed to show relationships across rows and columns, but a table with many columns may require more horizontal space than a small screen can provide.

If the table is forced to shrink too much, cell content may wrap excessively or become difficult to read. If it does not shrink, the table may extend beyond the viewport and cause the page itself to scroll horizontally.

Create a Scrollable Table

One of the simplest responsive techniques is to wrap the table in another element and allow that wrapper to scroll horizontally when needed.

<div class="table-responsive">
  <table>
    ...
  </table>
</div>
.table-responsive {
  overflow-x: auto;
}

The table keeps its normal row-and-column structure, while only the table area becomes horizontally scrollable on narrower screens.

Responsive Table Wrapper

The responsive wrapper controls overflow without changing the meaning of the table itself.

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

Using a wrapper also helps prevent the entire webpage from becoming wider than the viewport when the table contains more content than can comfortably fit on the screen.

Table Width and Content

Tables can often use the full width of their container, but the data inside the cells ultimately determines how narrow the table can become.

table {
  width: 100%;
  border-collapse: collapse;
}

Long words, URLs, numbers, or several columns can make a table require additional width. In those cases, horizontal scrolling is often preferable to compressing the content until it becomes difficult to read.

Preserve Table Structure

Responsive design should not remove the semantic relationships that make a table understandable. Avoid changing table elements into unrelated layout structures simply to make the table fit a small screen.

Keeping <table>, <tr>, <th>, and <td> intact preserves the relationships between headers and data while CSS handles the visual presentation.

Responsive Tables and Accessibility

A responsive table should remain understandable and navigable when viewed at different screen sizes. Header cells, captions, and other semantic table elements should remain in the markup regardless of how the table is visually presented.

When horizontal scrolling is used, make sure users can reach all of the table content with normal touch, mouse, and keyboard interaction. Avoid hiding important columns unless there is another accessible way to obtain the same information.

Responsive Table Example

The following example places a wide table inside a horizontally scrollable container. Resize the editor window to make it narrower and watch the scrollable area appear while the table structure remains unchanged.

Play in Editor

Responsive Table Best Practices

  • Keep the semantic HTML table structure intact whenever possible.
  • Place wide tables inside a wrapper with overflow-x: auto.
  • Allow the table container to use the available width of the page.
  • Avoid forcing columns to become so narrow that the data is difficult to read.
  • Keep captions, headers, and other accessibility information in the table markup.
  • Do not hide important table data solely to make the table fit a smaller screen.
  • Test tables at several viewport widths to make sure every column remains reachable.
  • Use more advanced responsive patterns only when the data and design genuinely require them.

Summary

Responsive HTML tables should preserve the meaningful relationships between rows, columns, headers, and data while adapting to smaller screens. Wrapping a wide table in a container with horizontal overflow is a simple and reliable approach that keeps the table readable, accessible, and usable without changing its semantic structure.