Focused Field Groups
Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 17 of 55.
A field can contain a label, input and help link. A group-level focus cue helps users see which cluster they are working with. The focus-within: variant matches a wrapper whenever that wrapper or one of its descendants has focus.
<div class="outline-solid outline-0 outline-offset-2 focus-within:outline-4"><label for="search">Search</label><input id="search"><a href="#searchHelp">Help</a></div>The example starts with a zero-width outline and adds a 4px outline while the input or help link is focused. outline-solid provides the line style and outline-offset-2 separates it from the group edge by 2px. Outlines do not consume layout space like borders.
Keep the control’s own focus indicator. Group emphasis is additional orientation, not a reason to erase keyboard focus. When focus leaves the group, its base outline should return.
Challenge
MediumGive the email group no outline at rest. While any descendant has focus, show a solid 2px outline with a 4px offset. Keep that cue when focus moves from the input to its help link, and remove it after focus leaves the group. Preserve the control’s own focus behavior.
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="group" class="p-4 outline-solid outline-0 outline-offset-4"><label for="email">Email</label><input id="email" type="email" class="block border"><a id="help" href="#helpText">Email help</a></div><button id="outside">Continue later</button><p id="helpText">Use an address you can access.</p>
</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