Menu
CoddyTech

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 icon

Challenge

Medium

Give 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>
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