Tag outline-style

🎨 CSS outline-style: Defining the Look of Element Outlines

The outline-style CSS property controls the pattern or style of the outline drawn around an element. Unlike borders, outlines don’t affect layout size, and by adjusting their style, you can create distinct visual effects to highlight elements, indicate focus, or debug your layout.


🧾 What is outline-style?

outline-style specifies the line style of the outline, such as solid, dashed, dotted, or none. For the outline to appear, you must set a style other than none. Without a valid style, outlines won’t be visible regardless of color or width.


🧬 Syntax

selector {
outline-style: <style>;
}

Possible values:

ValueDescription
noneNo outline shown (default)
solidA continuous solid line
dottedSeries of dots
dashedSeries of short dashes
doubleTwo solid lines with space between
groove3D grooved effect (looks carved)
ridge3D ridged effect (looks raised)
inset3D inset effect (pressed into page)
outset3D outset effect (pops out from page)
initialResets to default (none)
inheritInherits the style from parent

🎯 Example Usage

1. Solid outline for focus state

input:focus {
outline-style: solid;
outline-width: 2px;
outline-color: blue;
}

Creates a clean solid blue outline on focus.


2. Dashed outline for emphasis

button:hover {
outline-style: dashed;
outline-color: orange;
outline-width: 3px;
}

Highlights buttons on hover with a dashed orange outline.


3. Removing outline for mouse users

button:focus:not(:focus-visible) {
outline-style: none;
}

Removes outlines when focus is not visible (commonly for mouse users) while keeping them for keyboard users.


🧠 Outline Style in Shorthand

You can set the outline style along with width and color using the shorthand:

element {
outline: 4px dotted green;
}

This sets the outline width to 4px, style to dotted, and color to green in one line.


⚠️ Accessibility Tips

  • Don’t remove outlines completely; they are vital for keyboard navigation and accessibility.
  • Customize outlines carefully, ensuring high contrast and visible styles.
  • Use outline-style to enhance usability without removing the focus indicator.

✅ Browser Support

The outline-style property is supported across all modern browsers, including:

  • ✅ Chrome
  • ✅ Firefox
  • ✅ Safari
  • ✅ Edge
  • ✅ Internet Explorer 8+

🔚 Conclusion

outline-style is a simple yet powerful CSS property that controls how outlines look around elements. Whether you want a subtle dotted effect, a strong solid line, or a 3D groove, outline-style helps make your UI intuitive, accessible, and visually distinct — all without affecting layout.