Menu
CoddyTech

Responsive Field Groups

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

A form layout should keep each label close to its control. Wrap each pair in a field group and place those groups on the grid. The label’s for must continue to match the input’s id; CSS positioning is not a replacement for that relationship.

<form class="grid grid-cols-1 sm:grid-cols-2 gap-3"><div><label for="topic">Topic</label><input id="topic"></div><div class="col-span-full"><label for="message">Message</label><textarea id="message"></textarea></div></form>

The example uses one column until 640px and two afterward. Its long message group spans the explicit grid with col-span-full. The same span works when there is only one track, so the narrow form stays simple.

Use full-row groups for long text, explanations or submit actions when the short fields use several columns. Keep both row and column gaps deliberate so stacked labels and neighboring fields remain separated.

challenge icon

Challenge

Medium

Stack the booking fields below 768px. At 768px and wider, use two equal columns. Keep 16px gaps on both axes and make the Notes group span the full form width at every size. Preserve all explicit label 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>
<form id="form" class="w-full max-w-[416px] grid grid-cols-1"><div><label for="name">Name</label><input id="name" class="block w-full"></div><div><label for="city">City</label><input id="city" class="block w-full"></div><div id="notesGroup" class=""><label for="notes">Notes</label><textarea id="notes" class="block w-full"></textarea></div></form>
</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