CSSApril 2026 ยท 5 min read

How to Create CSS Outlines and Focus Styles

CSS outline is an underappreciated property that's essential for accessibility. It draws a line around an element without affecting layout โ€” unlike border, which adds to the element's size. Outlines are the standard way to indicate keyboard focus, and customizing them properly ensures your site is both accessible and visually polished.

๐Ÿ”ฒ
Try the CSS Outline Generator
Free, no signup
โ†’
DG
Derek Giordano
Designer & Developer
In this guide
01Outline vs Border02WCAG-Compliant Focus Styles03Custom Focus Ring Techniques04Never Remove Outlines Without Replacement
โšก Key Takeaways
  • Style CSS outlines for focus indicators, decorative borders, and accessibility.
  • Covers outline vs border.
  • Covers wcag-compliant focus styles.
  • Covers custom focus ring techniques.
  • Covers never remove outlines without replacement.

Outline vs Border

Border is part of the box model โ€” it adds to the element's dimensions and affects layout. Outline sits outside the border and doesn't affect size or position. Border follows border-radius; outline is rectangular by default (though modern browsers now support outline rounding in most cases). Use border for decorative styling, outline for focus indicators.

WCAG-Compliant Focus Styles

WCAG requires visible focus indicators for keyboard navigation. The default browser outline works but is often too subtle:

๐Ÿ’ก Tip
Stick to animating transform and opacity for smooth 60fps performance. These properties are handled by the GPU compositor and skip expensive layout recalculations.

:focus-visible {

outline: 2px solid #00FFD1;

outline-offset: 3px;

}

:focus-visible only shows the outline for keyboard navigation (not mouse clicks), which is what users expect. The outline-offset creates space between the element and the outline, preventing visual cramping. The CSS Outline Generator lets you preview different outline styles and offsets.

Custom Focus Ring Techniques

For rounded focus rings that follow border-radius, use box-shadow instead of outline:

โš  Warning
Avoid animating width, height, top, or left. These trigger layout recalculations on every frame and can drop performance below 60fps.

:focus-visible {

outline: none;

box-shadow: 0 0 0 3px rgba(0, 255, 209, 0.5);

}

This creates a soft glow ring that respects border-radius. The downside is that box-shadow doesn't show in Windows High Contrast Mode โ€” so always include a transparent outline as a fallback:

:focus-visible {

outline: 2px solid transparent;

box-shadow: 0 0 0 3px rgba(0, 255, 209, 0.5);

}

Never Remove Outlines Without Replacement

outline: none or outline: 0 without a visible replacement is an accessibility violation. Keyboard users rely on focus indicators to know where they are on the page. If the default outline doesn't match your design, replace it โ€” don't remove it.

Frequently Asked Questions

What is the difference between outline and border?+
Outline doesn't affect element size or layout. Border adds to the element's box model dimensions. Outline sits outside the border and is primarily used for focus indicators.
How do I make accessible focus styles?+
Use :focus-visible with a visible outline (at least 2px) that contrasts against the background. Add outline-offset for spacing. Never remove the outline without providing an equally visible alternative.
Why use :focus-visible instead of :focus?+
focus-visible only shows the focus indicator for keyboard navigation, not mouse clicks. This gives keyboard users the indicator they need without adding visual noise for mouse users.
Try it yourself

Use the CSS Outline Generator โ€” free, no signup required.

โšก Open CSS Outline Generator
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.