Focus Ring Generator
Set the ring color, thickness, offset and style, and watch it applied to a button, a text input and a link with the focus state always on. The tool measures the ring against every color it touches for WCAG 1.4.11 Non-text Contrast (3:1): the surface behind it, and the component too when the offset is 0. Choose a plain outline or a box-shadow ring, and copy a :focus-visible rule that matches the preview declaration for declaration.
How to Build an Accessible Focus Ring
- Set the colors - Pick Ring color, Surface behind it and Component color with the pickers or hex fields. Hex accepts 3 or 6 digits, and a bad value is flagged.
- Shape the ring - Drag Thickness and Offset, and pick Solid, Dashed or Dotted in Style. The button, input and link update at once.
- Choose a technique - Select Outline, or Box-shadow ring, which draws a solid ring with a surface-colored gap and turns Style off.
- Check the contrast - Read the ratio against the surface, and against the button when Offset is 0. If a row says Fails 3:1, change the ring color or raise Offset.
- Copy the CSS - Press Copy CSS to take the
:focus-visiblerule and the:focus:not(:focus-visible)reset.
Why a focus ring needs two contrast checks
WCAG 1.4.11 asks for 3:1 between the focus indicator and the colors next to it. With a gap (offset above 0) the neighbor is the surface. With offset 0 the ring touches the component as well, so a blue ring on a blue button measures 1:1 even when it passes against white. The ratio is never rounded: #959595 on white is 2.995:1 and shows as 2.99 and Fails. SC 2.4.13 Focus Appearance (AAA) adds an area minimum equal to a 2 px thick perimeter. The tool judges solid rings against it and says so plainly when dashed or dotted coverage is not checked.
In forced-colors modes such as Windows high contrast, outlines stay visible with their color replaced, while box-shadow is removed. The Outline technique therefore survives on its own. The Box-shadow ring writes a transparent outline next to the shadow so it still shows there. Offset becomes a surface-colored inner shadow, because box-shadow has no offset of its own.
:focus-visible shows the ring for keyboard focus and mostly hides it for mouse clicks, and the reset rule leaves the browser default alone where the selector is unsupported. This tool does not check SC 2.4.11 Focus Not Obscured: a sticky header can still cover the ring, so tab through your page too.