Skip to main content

CSS Responsive Tables

A responsive table shows a horizontal scrollbar when the screen is too small to fit the whole table.

To make one, wrap the <table> in a <div> container and set overflow-x: auto on that <div>.

Note: On macOS, scrollbars are hidden by default and only show while being used, even when overflow scrolling is set.

Example

A wide table wrapped in a div with overflow-x: auto scrolls sideways on small screens.

Prompt
An HTML page with a responsive table that scrolls horizontally on small screens. In an internal <style> block, style a table (collapsed borders, full width, padded bordered cells) and add a div.tablecontainer rule with overflow-x: auto. In the body, wrap a wide table (many columns) inside a div with class "tablecontainer". On a narrow window the table should get a horizontal scrollbar.
Output: complete HTML page