Creating Responsive Tables

To make a large HTML table responsive on smaller screens, wrap the table in a div container and apply the CSS property overflow-x: auto; to that wrapper.

Tables are notoriously difficult to display on mobile devices because they require a rigid grid. If you have too many columns, the table will either break your website layout or squash the data until it's unreadable.

The standard, most user-friendly solution isn't to change the table itself, but to allow the user to swipe horizontally just for the table area.

The Wrapper Method

First, wrap your table in a simple div element. We will give it a class so we can target it with CSS:

Then, apply the scrolling rule to the class in your CSS:

Adding overflow-x: auto; tells the browser: "If the content inside this div is wider than the screen, hide the extra content, but show a horizontal scrollbar so the user can still reach it".

Preventing Text Wrap

Sometimes, before a table triggers the scrollbar, it will attempt to squeeze the content by wrapping the text inside the cells onto multiple lines, making the table very tall and ugly. You can prevent this using the white-space property on your cells:

Full Working Example

In the following example, try resizing your browser window (or using a mobile device). You will notice that as the screen gets smaller, a scrollbar appears at the bottom of the table, while the rest of the page remains unaffected.

View Output Full Screen Preview