Create a responsive table with CSS horizontal scrolling

To keep columns readable on a narrow screen, give the table a suitable min-width and set overflow-x: auto on its wrapper. The table keeps enough space for comparison, and only the wrapper scrolls when space runs out.

Give the table a minimum width and its wrapper the scroll

In the example, width: 100% lets the table fill its wrapper when there is enough room. min-width: 640px keeps it from shrinking further. The wrapper handles the excess width inside its own scroll area. Treat 640px as a starting point for this data set. See CSS Overflow · auto.

Try the complete study-plan table

Save the code as responsive-table.html and open it. The study-plan table runs on its own without external files.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Tables on small screens</title>
  <style>
    body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
    * { box-sizing: border-box; }
    main { max-width: 900px; min-width: 0; }
    h1 { font-size: 24px; }
    .jb-table-scroll { max-width: 100%; overflow-x: auto; border: 1px solid #8ca0b3; }
    .jb-table-scroll:focus-visible { outline: 3px solid #146bcc; outline-offset: 3px; }
    .jb-table-01 { width: 100%; min-width: 640px; border-collapse: collapse; }
    caption { padding: 10px; text-align: left; font-weight: 700; }
    th, td { padding: 12px; border-bottom: 1px solid #a5b5c4; text-align: left; vertical-align: top; }
    thead th { background: #173f65; color: #fff; }
    tbody th { white-space: nowrap; }
    tbody tr:nth-child(even) { background: #edf3fa; }
    .short { white-space: nowrap; }
  </style>
</head>
<body>
<main>
  <h1>Tables on small screens</h1>
  <p id="table-help">If the table is too wide, scroll sideways inside it. With a keyboard, Tab to the table region and use the arrow keys.</p>
  <div class="jb-table-scroll" tabindex="0" role="region" aria-label="Study plan table" aria-describedby="table-help">
    <table class="jb-table-01">
      <caption>Sample study plan</caption>
      <thead><tr><th scope="col">Topic</th><th scope="col">Lesson</th><th scope="col">Tools</th><th scope="col">What to check</th></tr></thead>
      <tbody>
        <tr><th scope="row">HTML</th><td>Build a form</td><td class="short">Editor and browser</td><td>Check the labeled input fields and the submit button.</td></tr>
        <tr><th scope="row">CSS</th><td>Style a table</td><td class="short">Editor and browser</td><td>Check the header row, alternating row colors, and horizontal scrolling.</td></tr>
        <tr><th scope="row">JavaScript</th><td>Wire up a button</td><td class="short">Editor and browser</td><td>Check that pressing the button changes the message.</td></tr>
      </tbody>
    </table>
  </div>
  <p>This paragraph and the rest of the page should stay in place while the table scrolls.</p>
</main>
</body>
</html>

In a wide window the table fills the available content width. When the wrapper gets narrower than the table, scroll inside it to reach the last column. If the paragraph below also shifts sideways, the page itself is overflowing. A text instruction is included because some systems show scrollbars only while scrolling.

Adjust cell spacing and wrapping

Give the table a caption and associate header cells with their columns or rows using scope="col" and scope="row". These associations help screen readers present the data in context. The example adds cell padding, combines adjoining borders with border-collapse: collapse, and shades only even rows in tbody. See W3C WAI · Tables with Two Headers.

Change only the table’s min-width from 640px to 480px and compare the horizontal travel and the line breaks in the description cells. Restore 640px afterward. Reserve white-space: nowrap for short labels and tool names. If translations or long URLs force a column to grow, let the affected cells wrap.

Check keyboard access and page overflow

The wrapper’s tabindex="0" places it in the Tab order. Tab to it and check that the left and right arrow keys scroll to hidden columns. Keep a visible focus outline. Use aria-label to name the region and aria-describedby to link the scrolling instructions.

If the whole page still scrolls sideways, check whether a flex or grid item containing the table can shrink. If its content-based minimum is holding it open, try min-width: 0 on that item and confirm the wrapper still scrolls. Sideways scrolling can be appropriate for data that needs a row-and-column comparison. See WCAG · Reflow for the distinction between ordinary page text and content that needs a two-dimensional layout.