Menu
CoddyTech

Predictable Table Columns

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

A fixed table layout is useful when a data view needs predictable column widths. Combine table-fixed with an explicit table width. Unlike content-driven automatic layout, the fixed algorithm can use column definitions and the first row to establish tracks.

<table class="table-fixed w-[512px]"><colgroup><col class="w-32"><col></colgroup><tbody><tr><td>A1</td><td>Description</td></tr></tbody></table>

The worked example reserves 128px for a code column in a 512px table, leaving 384px for its description. A colgroup lets the width policy live alongside the table structure instead of being repeated on every cell.

Fixed sizing does not decide what to do with long text. Keep wrapping or truncation intentional and preserve full data where the interface needs it. This task uses short supplied content so the column sizing can be inspected directly.

challenge icon

Challenge

Medium

Use fixed table layout for the supplied 600px table. Reserve 160px for the first column and let the second use the remaining 440px. Preserve the column group, caption and all header relationships.

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>
<table id="table" class="w-[600px] border-collapse table-auto"><caption>Studio schedule</caption><colgroup><col class=""><col></colgroup><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>
</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