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
MediumStack 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>
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Responsive UI Patterns
1Page Shells
Growing Page ShellsFlexible Content RailsBounded Scroll RegionsFull-Bleed RegionsRecap: Page Shells4Form Layouts
Responsive Field GroupsFocused Field GroupsSelectable Form OptionsNative Validation CuesRecap: Form Layouts2Navigation Patterns
Wrapping NavigationCurrent Page CuesNative Menu DisclosuresKeyboard Skip LinksRecap: Navigation5Data Tables
Scrollable Data TablesPredictable Table ColumnsRow State PresentationSticky Table HeadersRecap: Data Tables8Interactive Panels
Expanded Control CuesChoice Card StatesFocus-Aware Help PanelsContent-Aware Empty StatesRecap: Interactive Panels11Project: Event Portal
Portal ShellSession Browser