Outlines and Focus Indicators: outline, outline-offset and Accessible Focus Styles
Outlines and how they differ from borders: no layout effect, one style for all sides, outline-offset, the auto style and rounded outlines, plus accessible focus indicators with :focus-visible, WCAG rules, two-color rings, forced colors and sticky headers.
kvi5hnuCode Sprout team member8 min readOn this page
An outline is a line drawn around an element, like a border, with one crucial difference: it takes up no space. Adding or changing an outline never moves anything on the page. That's why browsers use outlines for focus indicators, the ring that shows which element receives keyboard input, and why most outline work is really about making focus visible.
Outlines versus borders
| Border | Outline | |
|---|---|---|
| affects layout | yes: part of the box's size | no: drawn on top, over neighbors if needed |
| sides | each side can differ | one style, width and color for the whole outline |
| position | between padding and margin | outside the border edge, moved with outline-offset |
auto style | no | yes: the browser's native focus ring |
follows border-radius | yes | yes, in all current browsers |
| on wrapped inline elements | sliced per line | browsers draw around each line fragment, or merge them |
Because outlines don't take space, they can overlap neighboring content, and a parent with overflow: hidden (article 43) can clip them.

The 8px difference is the left and right border. The outline in the bottom row overlaps its neighbors instead of pushing them.
The properties
.card:focus-visible {
outline: 3px solid #8a3b12; /* width, style, color, in any order */
outline-offset: 3px;
}
| Property | Initial value | Notes |
|---|---|---|
outline-style | none | the border styles, plus auto; no hidden |
outline-width | medium (3px) | a length or thin, medium, thick; no percentages |
outline-color | the text color | any color; the old invert value is gone from browsers |
outline-offset | 0 | space between the border edge and the outline; negative values draw it inside the box |
outline | shorthand for style, width and color (not offset) |
As with borders, an outline needs a style to appear. Unlike borders, outline-width keeps its value when the style is none, which only matters if you read it from JavaScript.
outline-style: auto
auto asks for the browser's native focus ring, whatever the platform draws: in Chrome, a two-tone blue and white ring that stays visible on light and dark backgrounds. It's what browsers use by default for focus:
:focus-visible { outline: auto; } /* roughly what browsers do */
With auto, the browser may ignore your width, and in some browsers your color. Use it when you want the native look.
Focus indicators
Keyboard users, switch users and many screen reader users move through a page with Tab and the arrow keys. The focus indicator is their cursor: without it, they can't tell where they are. Browsers show one by default, and the most important rule is don't remove it without a replacement:
/* ❌ never do this on its own */
button:focus { outline: none; }
:focus-visible
:focus-visible (article 11) matches when the browser decides a focus indicator should be shown: always for keyboard focus, and for text fields however they're focused, but usually not when a button is clicked with a mouse. That's what lets designers drop the ring for mouse clicks without hurting keyboard users:
.btn:focus-visible {
outline: 3px solid #8a3b12;
outline-offset: 2px;
}
Browsers' default styles already use :focus-visible, so a plain :focus { outline: none } reset is no longer needed to hide rings on click; it only removes them for keyboard users.
What makes a good indicator
WCAG 2.2 has several requirements for focus:
- Focus visible (2.4.7, level AA): any keyboard-operable element must have a visible indicator.
- Non-text contrast (1.4.11, AA): the indicator needs at least 3 contrast against what's next to it.
- Focus not obscured (2.4.11, AA): the focused element mustn't be entirely hidden by other content, such as a sticky header.
- Focus appearance (2.4.13, AAA): an indicator at least as large as a 2px outline around the element, with 3 contrast between the focused and unfocused states.
A solid outline of 2 to 3px, offset a couple of pixels, in a color that contrasts with both the element and the page, meets the indicator requirements. "Focus not obscured" depends on the layout instead (see sticky headers below).
body { font: 1rem system-ui, sans-serif; margin: 1rem; display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
nav { display: flex; gap: 0.75rem; }
p { flex-basis: 100%; margin: 0.25rem 0 0; font-size: 0.85rem; color: #555; }
a { color: #8a3b12; padding: 0.2rem; }
.ring:focus-visible { outline: 3px solid #8a3b12; outline-offset: 3px; border-radius: 4px; }
.btn { font: inherit; padding: 0.5rem 0.9rem; border: 0; border-radius: 8px; background: #2f7d4f; color: white; }
.btn:focus-visible { outline: 3px solid #1f5636; outline-offset: 3px; }
.dual:focus-visible { outline: 3px solid white; outline-offset: 0; box-shadow: 0 0 0 6px #2b2118; }
.field { font: inherit; padding: 0.45rem; border: 1px solid #8a8070; border-radius: 6px; width: 9rem; }
.field:focus-visible { outline: 2px solid #8a3b12; outline-offset: -2px; border-color: #8a3b12; }
Some techniques shown here:
- Offset outlines (
outline-offset: 2pxto4px) leave a gap, so the ring is visible even on an element of the same color as the outline. - Two-color rings keep contrast on any background: a white outline with a dark
box-shadowoutside it, or the reverse. That matters for components used on both light and dark surfaces. - Negative offsets draw the ring inside the element, useful where an outside ring would be clipped, such as items in a scrolling list or table cells.
- Outlines follow
border-radius, so a rounded button gets a rounded ring.

The single-color ring passes on one surface and fails on the other. The two-color ring is the one that works on both.
Focus styles and forced colors
In forced colors mode (article 35), box-shadow is removed, but outlines stay and get a system color. A focus style made only of box-shadow disappears. Always include an outline, even a transparent one, which forced colors mode makes visible:
.chip:focus-visible {
outline: 2px solid transparent; /* visible in forced colors */
box-shadow: 0 0 0 3px #f4c95d; /* visible otherwise */
}
Focus inside components
:focus-within matches an element that contains the focused element. It highlights a whole group, such as a search box with a button, or a card whose link is focused:
.search:focus-within { outline: 2px solid #8a3b12; outline-offset: 2px; }
.search input:focus-visible { outline: none; } /* the group shows focus instead */
Removing the inner outline is fine here, because the group's outline replaces it. For a card, :has(:focus-visible) (article 12) is more precise, since it ignores mouse clicks.
Sticky headers hiding focus
A sticky or fixed header (article 57) can cover a focused element when the page scrolls to it, which fails "focus not obscured". scroll-padding-top on the scroll container tells the browser to keep that area clear when it scrolls focused elements and anchor targets into view:
html { scroll-padding-top: 5rem; } /* the header's height, plus a little */
Outlines as a debugging tool
Since outlines don't affect layout, they're perfect for seeing boxes without moving them:
* { outline: 1px solid rgb(255 0 0 / 0.4); }
Every element gets a faint red frame, and the layout stays exactly the same. DevTools' layout overlays do the same job with more detail.
What's current
- Outlines follow
border-radiusin all current browsers; Safari was the last, in 2023. :focus-visibleis Baseline widely available, and browsers' default focus styles use it.outline-color: inverthas been removed from browsers.- WCAG 2.2 added "focus not obscured" (AA) and "focus appearance" (AAA).
Common questions
Can I remove focus outlines?
Only if you replace them with another clearly visible indicator. Use :focus-visible to style keyboard focus, and the browser won't show it for mouse clicks on buttons anyway.
Why is my focus outline cut off?
A parent clips overflow (overflow: hidden or auto), or a neighbor covers the outline. Use a negative outline-offset to draw it inside, or remove the clipping.
Can I set an outline on one side only?
No. Outlines are all-or-nothing. For a single line, use a border, or a box-shadow with an offset, such as box-shadow: 0 3px 0 #8a3b12.
Does outline-offset work with outline: auto?
Usually yes, though the native ring's look varies between browsers.
What's the difference between :focus, :focus-visible and :focus-within?
:focus matches whenever an element has focus. :focus-visible matches when the browser thinks focus should be shown, mainly keyboard focus. :focus-within matches an element when it or anything inside it has focus.
Summary
- Outlines are drawn outside the border and never affect layout. They have one style, width and color for all sides.
outline-offsetmoves the outline out, or in with negative values. Outlines followborder-radius.outline-style: autogives the browser's native focus ring.- Never remove focus indicators without a replacement. Style them with
:focus-visible. - Good indicators are at least 2px thick, with 3 contrast; offsets and two-color rings help.
- Include an outline in every focus style for forced colors mode, and use
scroll-paddingso sticky headers don't hide focus.
Practice questions
Write a focus style for .btn that shows a 3px rust outline (#8a3b12) with a 2px gap, only for keyboard focus.
Answer
.btn:focus-visible { outline: 3px solid #8a3b12; outline-offset: 2px; }
A focus style is box-shadow: 0 0 0 3px gold; only. Name two problems and fix them.
Answer
Gold on a light background may not reach 3 contrast, and shadows are removed in forced colors mode, so the indicator disappears. Add outline: 2px solid transparent; (or a real outline), and use a darker color or a two-color ring.
Items in a scrolling list with overflow: auto show cut-off focus rings. What can you change on the items?
Answer
Draw the outline inside the item with a negative offset, such as outline: 2px solid #8a3b12; outline-offset: -2px;.
A page has a 4rem sticky header, and tabbing to links near the top of the viewport hides them under it. Fix it in CSS.
Answer
html { scroll-padding-top: 4.5rem; }
The browser then keeps that area clear when it scrolls focused elements into view.
Previous: Borders: Styles, Widths, Colors, border-radius, border-image and corner-shape
Next: Overflow: Scroll Containers, overflow: clip, text-overflow, line-clamp and Scrollbars

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.