Menu
CoddyTech

Scrollable Data Tables

Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 21 of 55.

Data tables express relationships between rows and columns. Preserve table, caption and header cells rather than replacing them with visually similar boxes. Use scope="col" and scope="row" for the corresponding header relationships.

<div class="w-full overflow-x-auto"><table class="w-full min-w-[600px]"><caption>Room assignments</caption><thead><tr><th scope="col">Room</th></tr></thead><tbody><tr><td>Studio A</td></tr></tbody></table></div>

On a narrow screen, a table may need more width than the viewport. Put overflow-x-auto on a wrapper and a minimum width on the table. The example gives the table a 600px minimum while allowing its wrapper to use the available width.

The wrapper is the viewing region; the table is the wider content. Do not clip the final columns or create a separate scroll area for every cell. Keep the caption visible as context for the data.

challenge icon

Challenge

Medium

Keep the studio table at least 640px wide inside a full-width wrapper capped at 480px. Make the wrapper horizontally scrollable instead of clipping columns. Preserve the caption, column headers and row headers.

Preserve the supplied content, semantic elements and IDs. Edit the requested utility classes. Press Run preview after edits, then Check/Run code to grade the result. Supplied JavaScript is read-only.

Try it yourself

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Interface workshop</title><link rel="stylesheet" href="./styles.css"></head><body>
<div id="wrap" class="w-full max-w-[480px] overflow-hidden"><table id="table" class="w-full"><caption>Studio schedule</caption><thead><tr><th scope="col" class="">Session</th><th scope="col" class="">Room</th></tr></thead><tbody><tr id="r1" class=""><th scope="row">Session 1</th><td id="cell1">Room 1</td></tr><tr id="r2" class=""><th scope="row">Session 2</th><td id="cell2">Room 2</td></tr><tr id="r3" class=""><th scope="row">Session 3</th><td id="cell3">Room 3</td></tr></tbody></table></div>
</body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Responsive UI Patterns