CSS outline-style Property
The CSS outline-style property specifies the line style used to draw an outline around an element.
Outlines can be solid, dashed, dotted, double, or rendered with a three-dimensional appearance. They are commonly used to highlight interactive elements, particularly buttons, links, and form controls that receive keyboard focus. Unlike borders, outlines do not affect an element's layout dimensions.
outline-style Syntax
The outline-style property accepts one outline style keyword. Width and color are controlled separately or through the outline shorthand.
Basic Syntax
selector {
outline-style: solid;
}
Solid Outline
.box {
outline-style: solid;
}
Dashed Outline
.box {
outline-style: dashed;
}
Dotted Outline
.box {
outline-style: dotted;
}
Double Outline
.box {
outline-style: double;
}
Automatic Outline
.box {
outline-style: auto;
}
Removing an Outline
.box {
outline-style: none;
}
CSS-Wide Keywords
.box {
outline-style: initial;
}
.box {
outline-style: inherit;
}
.box {
outline-style: unset;
}
.box {
outline-style: revert;
}
.box {
outline-style: revert-layer;
}
The initial value is none, so an outline is not normally visible unless a different style is applied or supplied by browser styles.
Property Values
The outline-style property supports the following line styles.
| Value | Description |
|---|---|
none |
No outline is drawn. This is the initial value. |
hidden |
No outline is drawn. For outlines, its visual effect is equivalent to none. |
dotted |
Draws an outline consisting of dots. |
dashed |
Draws an outline consisting of short dashes. |
solid |
Draws a continuous outline. |
double |
Draws two parallel lines within the specified outline width. |
groove |
Draws an outline with a carved or grooved appearance. |
ridge |
Draws an outline with a raised appearance. |
inset |
Draws an outline with an inset appearance. |
outset |
Draws an outline with an outset appearance. |
auto |
Allows the browser to choose a platform-dependent outline style. |
initial |
Resets the property to none. |
inherit |
Uses the computed outline style of the parent element. |
unset |
Resets the property to none because it is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | none |
| Inherited | No |
| Applies to | All elements |
| Computed value | Specified keyword |
| Animation type | Discrete |
| Affects layout | No |
| Related shorthand | outline |
Valid Values
.box {
outline-style: solid;
}
.box {
outline-style: dashed;
}
.box {
outline-style: dotted;
}
.box {
outline-style: double;
}
.box {
outline-style: groove;
}
.box {
outline-style: auto;
}
Invalid Values
.box {
outline-style: 3px;
}
.box {
outline-style: blue;
}
.box {
outline-style: 50%;
}
These declarations are invalid because outline-style accepts style keywords rather than lengths, colors, or percentages.
How It Works
The outline-style property determines how the outline line is drawn. It works with outline-width and outline-color to produce the complete outline.
Setting an Outline Style
.box {
outline-width: 3px;
outline-style: solid;
outline-color: #2563eb;
}
The element receives a three-pixel solid blue outline.
Changing Only the Style
.box {
outline: 3px solid #2563eb;
}
.box.highlighted {
outline-style: dashed;
}
The highlighted element keeps the same outline width and color but changes from a solid line to a dashed line.
Outline Style and Layout
Changing the outline style does not affect the element's width, height, margin, padding, or layout position.
Outlines and Borders
An outline is generally drawn outside the element's border edge. The two can appear together, allowing the border to define the element's boundary and the outline to provide an additional highlight.
Important Consideration
The outline is not divided into independently styled sides. A single outline-style value controls the entire outline.
none and hidden
The none and hidden values prevent an outline from being drawn.
Using none
.box {
outline-style: none;
}
The outline is not displayed, even if an outline width and color have been specified.
Using hidden
.box {
outline-style: hidden;
}
The outline is also not displayed.
Setting a Width with none
.box {
outline-width: 5px;
outline-color: red;
outline-style: none;
}
No outline appears because the style is none.
Changing the Style Later
.box {
outline: 3px solid #2563eb;
}
.box.inactive {
outline-style: none;
}
The inactive element does not display an outline, while the other element retains its solid outline.
Accessibility Warning
Removing outlines from focused interactive elements can make keyboard navigation difficult. Do not remove the browser's default focus indicator without providing a visible replacement.
solid
The solid value draws a continuous line around the element. It is one of the most commonly used outline styles.
Basic Solid Outline
.box {
outline-style: solid;
outline-width: 3px;
outline-color: #2563eb;
}
Using the Shorthand
.box {
outline: 3px solid #2563eb;
}
Solid Outline with Offset
.box {
outline: 3px solid #2563eb;
outline-offset: 4px;
}
The outline is separated from the element's border edge by four pixels.
Solid Focus Indicator
button:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 3px;
}
A solid outline provides a clear and consistent focus indicator.
Important Consideration
Solid outlines are generally easier to distinguish than decorative styles, making them a practical choice for interactive elements.
dashed and dotted
The dashed and dotted values create outlines using repeated line segments or dots.
Dashed Outline
.box {
outline: 3px dashed #2563eb;
}
The outline consists of short dashes.
Dotted Outline
.box {
outline: 3px dotted #2563eb;
}
The outline consists of dots.
Changing Between Styles
.box {
outline: 3px dashed #2563eb;
}
.box:hover {
outline-style: dotted;
}
The outline changes from dashed to dotted when the element is hovered.
Dashed Focus Indicator
a:focus-visible {
outline: 2px dashed #2563eb;
outline-offset: 3px;
}
Important Consideration
The exact size and spacing of dashes and dots can vary between browsers. Use sufficient outline width and color contrast to maintain visibility.
double
The double value draws two parallel lines within the specified outline width.
Basic Double Outline
.box {
outline: 6px double #2563eb;
}
Double Outline with Offset
.box {
outline: 6px double #16a34a;
outline-offset: 4px;
}
Thin Double Outline
.box {
outline: 3px double #7c3aed;
}
A thin double outline may be difficult to distinguish because both lines and the gap must fit within the specified width.
Double Outline with a Border
.box {
border: 2px solid #64748b;
outline: 6px double #2563eb;
outline-offset: 5px;
}
Important Consideration
The specified outline width includes both lines and the space between them. The exact distribution of that width is determined by the browser.
3D Outline Styles
CSS provides four outline styles that simulate a three-dimensional appearance: groove, ridge, inset, and outset.
groove
.box {
outline: 6px groove #64748b;
}
The outline appears carved into the surrounding surface.
ridge
.box {
outline: 6px ridge #64748b;
}
The outline appears raised above the surrounding surface.
inset
.box {
outline: 6px inset #64748b;
}
The outline has an inset appearance.
outset
.box {
outline: 6px outset #64748b;
}
The outline has an outset appearance.
Comparing 3D Styles
| Style | Visual Effect |
|---|---|
groove |
Carved or recessed line |
ridge |
Raised line |
inset |
Inset appearance |
outset |
Outset appearance |
Important Consideration
Three-dimensional outline styles depend on browser rendering and the chosen outline color. Their visual effects may be subtle or differ between browsers.
auto
The auto value allows the browser to choose a platform-dependent outline style. It is commonly associated with browser-provided focus indicators.
Automatic Outline
.box {
outline-style: auto;
}
Automatic Focus Indicator
button:focus-visible {
outline-style: auto;
}
Using the Shorthand
button:focus-visible {
outline: auto;
}
Automatic Outline with Offset
button:focus-visible {
outline: auto;
outline-offset: 3px;
}
The browser chooses the outline's appearance, while the offset adds spacing around the focused element.
Important Consideration
Automatic outlines may differ in shape, width, and color across browsers and operating systems. Use an explicit outline style when consistent visual appearance is required.
Using the outline Shorthand
The outline shorthand combines outline-width, outline-style, and outline-color into one declaration.
Shorthand Declaration
.box {
outline: 3px solid #2563eb;
}
Equivalent Longhand Declarations
.box {
outline-width: 3px;
outline-style: solid;
outline-color: #2563eb;
}
Both examples produce the same outline.
Overriding the Style
.box {
outline: 3px solid #2563eb;
outline-style: dashed;
}
The final outline is dashed because the later longhand declaration overrides the style component.
Shorthand Reset Behavior
.box {
outline-style: dashed;
outline: 3px blue;
}
The later shorthand resets the style to none because no style is included. The declaration is valid, but no outline is drawn.
Using outline-offset
.box {
outline: 3px solid #2563eb;
outline-offset: 5px;
}
The outline-offset property is separate from the shorthand and controls the distance between the outline and the element's border edge.
Outline vs. Border
Outlines and borders support many of the same line styles, but they behave differently in layout.
| Feature | Outline | Border |
|---|---|---|
| Affects box dimensions | No | Yes, depending on box sizing |
| Individual side styles | Not supported | Supported |
Can use solid, dashed, and dotted |
Yes | Yes |
| Supports offset spacing | Yes, with outline-offset |
No equivalent border-offset property |
| Common use | Focus indicators and highlights | Element boundaries and decoration |
Border Style
.box {
border: 3px dashed #2563eb;
}
Outline Style
.box {
outline: 3px dashed #2563eb;
}
The border contributes to the box model, while the outline does not.
Using Both
.box {
border: 2px solid #64748b;
outline: 3px dashed #2563eb;
outline-offset: 4px;
}
The border and outline can use different styles without affecting each other's appearance.
Focus Indicators
Outlines help keyboard users identify the currently focused element. The outline-style property determines how the focus indicator is drawn.
Solid Focus Outline
button:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 3px;
}
Dashed Focus Outline
a:focus-visible {
outline: 2px dashed #2563eb;
outline-offset: 3px;
}
Automatic Focus Outline
input:focus-visible {
outline: auto;
}
Consistent Focus Styles
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 2px;
}
Important Consideration
Use focus indicators that remain clearly visible against different backgrounds. A solid outline is often a practical choice because its continuous line is easy to recognize.
Accessibility Considerations
Visible outlines are important for keyboard accessibility. Removing or weakening focus indicators can make it difficult to determine which interactive element is active.
Avoid Removing Focus Outlines
button:focus {
outline-style: none;
}
This removes the outline. Avoid this pattern unless another clear focus indicator is provided.
Provide a Visible Replacement
button:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 3px;
}
Maintain Sufficient Contrast
Choose an outline color and style that can be distinguished from adjacent backgrounds and element boundaries.
Forced Colors Mode
@media (forced-colors: active) {
:focus-visible {
outline: 2px solid Highlight;
outline-offset: 2px;
}
}
System colors help maintain focus visibility in forced-colors environments.
Avoid Subtle Focus Styles
Very thin dotted or dashed outlines may be difficult to see. Use sufficient width and contrast for focus indicators.
Important Consideration
Test interactive elements with the Tab and Shift+Tab keys to confirm that the focused element remains clearly identifiable.
outline-style Example
This example compares several outline styles. Each box uses the same outline color, allowing the differences between the line styles to be seen.
HTML Example
<div class="outline-style-demo">
<div class="outline-box style-solid">Solid</div>
<div class="outline-box style-dashed">Dashed</div>
<div class="outline-box style-dotted">Dotted</div>
<div class="outline-box style-double">Double</div>
<div class="outline-box style-groove">Groove</div>
<div class="outline-box style-ridge">Ridge</div>
<div class="outline-box style-inset">Inset</div>
<div class="outline-box style-outset">Outset</div>
</div>
CSS Example
.outline-style-demo {
display: flex;
flex-wrap: wrap;
gap: 24px;
padding: 24px;
background-color: #f1f5f9;
}
.outline-box {
display: flex;
align-items: center;
justify-content: center;
width: 100px;
height: 70px;
background-color: #fff;
color: #334155;
font-weight: 700;
outline-width: 6px;
outline-color: #2563eb;
}
.style-solid {
outline-style: solid;
}
.style-dashed {
outline-style: dashed;
}
.style-dotted {
outline-style: dotted;
}
.style-double {
outline-style: double;
}
.style-groove {
outline-style: groove;
}
.style-ridge {
outline-style: ridge;
}
.style-inset {
outline-style: inset;
}
.style-outset {
outline-style: outset;
}
The outlines use different line styles while retaining the same specified width and color. The exact appearance of the three-dimensional styles may vary between browsers.
Interactive Focus Example
This example changes a button's outline style when it receives visible keyboard focus.
<button class="outline-focus-button" type="button">Focus Me</button>
.outline-focus-button {
padding: 12px 20px;
border: 2px solid #2563eb;
background-color: #fff;
color: #1e40af;
cursor: pointer;
}
.outline-focus-button:focus-visible {
outline-width: 3px;
outline-style: dashed;
outline-color: #f97316;
outline-offset: 4px;
}
Use the Tab key to focus the button. A dashed orange outline appears outside its blue border.
Common Mistakes
Using Length Values
.box {
outline-style: 3px;
}
The declaration is invalid because outline-style accepts style keywords, not lengths.
Using Colors as Styles
.box {
outline-style: blue;
}
Use outline-color to specify an outline color.
Forgetting the Initial Style
.box {
outline-width: 3px;
outline-color: red;
}
No outline normally appears because the initial outline style is none.
Removing Focus Indicators
Using outline-style: none on focused elements can make keyboard navigation difficult unless another visible focus indicator is provided.
Expecting Layout Changes
Changing the outline style does not affect the element's box dimensions or position.
Confusing outline-style with border-style
outline-style controls the outline, while border-style controls the element's border.
Expecting Individual Side Styles
CSS does not provide separate outline-top-style, outline-right-style, outline-bottom-style, or outline-left-style properties.
Expecting Identical 3D Rendering
Groove, ridge, inset, and outset outlines may look different across browsers.
Forgetting Shorthand Resets
A later outline shorthand declaration resets omitted outline longhand values, including outline-style.
Important Considerations
Keep the following points in mind when using outline-style:
- The property controls the line style of an element's outline.
- Its initial value is
none. - The property is not inherited.
- It applies to all elements.
- It accepts predefined outline style keywords.
noneandhiddenprevent the outline from being drawn.soliddraws a continuous line.dasheddraws short line segments.dotteddraws dots.doubledraws two parallel lines.groove,ridge,inset, andoutsetcreate three-dimensional effects.autoallows browser-defined outline styling.- Outline styles do not affect layout dimensions.
- Outlines are generally drawn outside an element's border edge.
- Outline sides cannot be styled independently.
outline-widthcontrols the thickness of the outline.outline-colorcontrols the outline color.- The
outlineshorthand can set width, style, and color together. - A shorthand declaration resets omitted outline longhand values.
outline-offsetcontrols the distance between the outline and border edge.- Outlines are commonly used as keyboard focus indicators.
:focus-visibleis useful for applying focus styling.- Focus indicators should remain visible and have sufficient contrast.
- Browser rendering may vary for automatic and three-dimensional outline styles.
- Changes between outline style keywords animate discretely rather than blending continuously.
Browser Support
The CSS outline-style property is Baseline - Widely available and has been supported in major browsers for many years.
Modern versions of Chrome, Edge, Firefox, Safari, and other major browsers support standard outline styles.
The exact rendering of auto, dotted and dashed patterns, and three-dimensional outline styles may vary between browsers and operating systems.
For current compatibility information, visit Can I Use? and search for outline-style.
Specifications
The outline-style property is defined in CSS Basic User Interface Module Level 4.
CSS Basic User Interface Module Level 4: outline-style
The specification defines the available outline styles and their rendering behavior.
For additional documentation and examples, consult MDN Web Docs.
