Visible Keyboard Focus
Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 48 of 55.
A keyboard user needs to see which control will activate. focus-visible: follows the browser’s visible-focus indication state, which commonly appears during keyboard navigation. It is not the same as pointer hover.
<button class="outline-solid outline-0 outline-offset-2 focus-visible:outline-4">Open guide</button>The example replaces the base outline with a solid 4px cue and a 2px offset when visible focus applies. Only remove or zero a default outline when a clear replacement is supplied. The offset separates the cue from the control edge without changing layout dimensions.
Test Tab movement into and out of the control, including adjacent controls using the same rule. Keep the focused control visible and opaque; a computed outline on an invisible button is not a usable cue.
Challenge
MediumGive Reserve no custom outline at rest, then a solid 2px outline with 4px offset when it receives visible keyboard focus. The button must stay fully opaque and visible. Moving Tab to Finish must remove the cue from Reserve. Preserve native buttons and order.
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>
<button id="before">Start</button><button id="action" class="m-4 p-3 outline-solid outline-0 outline-offset-4">Reserve</button><button id="after">Finish</button>
</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 Layouts7Intrinsic Layouts
Auto-Fitting CollectionsResilient Label RowsMulti-Line PreviewsReadable Long TokensRecap: Intrinsic Layouts10Accessible Details
Direction-Aware SpacingComfortable Control TargetsVisible Keyboard FocusUnavailable Action StatesRecap: Accessible Details2Navigation 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