The outline property draws a highlight around an element without changing its size or pushing other content. It is especially useful for focus states and accessibility.
01
Highlight Ring
Draw around elements.
02
Shorthand
Width, style, color.
03
No Layout Shift
Unlike borders.
04
Focus Styles
Keyboard navigation.
05
Longhand Props
Split into parts.
06
outline-offset
Move outline outward.
Fundamentals
Introduction
The outline property in CSS is used to create an outline around elements. This outline is similar to a border but has some key differences, such as not affecting the layout or taking up space.
It’s often used to highlight elements, such as when a user interacts with form controls or navigates a page using the keyboard.
Definition and Usage
Use outline when you want a visible ring around an element without changing its width, height, or the position of nearby content.
For decorative boxes that should affect layout, use border instead. For keyboard focus indicators, outline is usually the better choice.
💡
Beginner Tip
Try outline: 3px solid #2563eb; on a button, then compare it with border: 3px solid #2563eb; to see how borders change layout but outlines do not.
Foundation
📝 Syntax
The outline property is a shorthand property for setting the following individual outline properties: outline-color, outline-style, and outline-width.
You can omit parts of the shorthand; omitted values reset to their defaults.
outline-style: none hides the outline even if width or color is set.
Outlines are drawn outside the border edge and do not affect box dimensions.
Use longhand properties when you need to change only one part of the outline.
Defaults
🎯 Default Value
The default value of the outline property is equivalent to medium none currentColor. This means that if no values are specified, the outline will not be visible.
Browsers may show a default focus outline on interactive elements until you style focus states yourself.
The border adds to the element’s box size. The outline is drawn outside without shifting siblings.
Companion
Longhand properties and outline-offset
Split the shorthand into outline-width, outline-style, and outline-color when you need finer control. Use outline-offset to push the outline farther away from the element.
Keep visible focus — Do not remove focus outlines without providing a clear replacement.
Use :focus-visible — Show strong outlines for keyboard users when possible.
Ensure contrast — Focus rings should stand out against the background.
Prefer outline over border for focus — Outlines avoid layout jumps when focus changes.
🧠 How outline Works
1
You set width, style, and color
The shorthand combines the three outline longhand properties.
Shorthand
2
The browser draws outside the border
The outline sits beyond the border edge and does not change box dimensions.
Layout
3
Optional offset adds spacing
outline-offset can move the ring farther from the element.
Offset
=
🔲
Clear highlight without layout shift
Elements gain a visible ring while nearby content stays in place.
Compatibility
Browser Compatibility
The outline property is widely supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is also well supported in older browsers, making it a reliable choice for styling.
✓ Baseline · Universal support
Excellent support everywhere
outline has long been supported and works reliably for focus and highlight styles.
99%Global browser support
Google Chrome1+ · All versions
Full support
Mozilla Firefox1.5+ · All versions
Full support
Apple Safari1.2+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera7+ · All versions
Full support
outline property99% supported
Bottom line:outline is one of the safest properties for focus and highlight styling.
Wrap Up
Conclusion
The outline property is a versatile tool for adding visual emphasis to elements on a webpage. It provides a simple way to enhance accessibility and highlight interactive elements without affecting the layout.
By adjusting the outline’s width, style, and color, you can create various visual effects that improve the user experience on your site.