Chapter 02 Foundations
Focus
One ring marks the keyboard on every control, 3:1 in both themes, for the keyboard only.
Tokens
Outside the edge on controls, inside it on list items.
| Token | Value | Tailwind | For | Sample |
|---|---|---|---|---|
--ui-focus | #0047cc · #8fb4ff | outline-focus | Ring colour, light and dark. 3:1 on the page. | |
--ui-focus-width | 3px | focus-visible:focus-ring | Ring thickness. | |
--ui-focus-offset | 2px | focus-visible:focus-ring-inset | Gap from the edge. Inset rings use minus the width. |
Try the ring
Both placements follow the tokens; the inset one uses minus the width.
Outside and inset
A button gets the ring outside; a menu item gets it inside, so its neighbours never cover it.
<!-- The tokens: --ui-focus-width: 3px; --ui-focus-offset: 2px -->
<button class="ui-button ui-button--primary">Save</button>
<a class="rounded-ui px-3 py-2 focus-visible:focus-ring" href="/orders">Orders</a>
<li class="px-3 focus-visible:focus-ring-inset" tabindex="-1">Invoices</li>Rules
- Dialogs take focus on open and hand it back on close.
- Lists keep focus on the control and ring the active option.
- A sticky header needs
scroll-padding-block-startso it never hides focus.