Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Borders, Outlines and Shadows

The outline property

Reference for the CSS outline shorthand: set outline width, style and color, how it differs from border, and why you should never remove focus outlines without a replacement.

The outline property draws a line around an element, outside its border edge. It is a shorthand for outline-width, outline-style and outline-color. Browsers use outlines to show which element has keyboard focus, so the property is mostly about focus styles.

Unlike a border, an outline takes up no space. It does not change the element's size or push neighbors around, and it is drawn on top of whatever is around it. Use outline-offset to move it away from the box.

CSS
button:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

Try it

Outline versus border

Syntax

CSS
outline: <outline-width> || <outline-style> || <outline-color>;
  • Initial value: medium none currentcolor (each part at its own initial value)
  • Applies to: all elements
  • Inherited: no
  • Animatable: yes (width, color; the style switches discretely)
  • Computed value: the computed values of the three longhands

The parts can come in any order, and each is optional. Note that the default style is none, so outline: 3px red; shows nothing: you must supply a style such as solid.

Values

Value Description
<outline-width> thin, medium, thick or a length such as 2px.
<outline-style> none, solid, dashed, dotted, double, groove, ridge, inset, outset, or auto.
<outline-color> Any color, or currentcolor.
none Removes the outline (style none).
auto Lets the browser draw its own focus ring (use as the style).

Usage notes

  • Never remove focus outlines without a replacement. outline: none makes the page unusable for people who navigate with the keyboard. Restyle the focus indicator instead, ideally with :focus-visible.
  • Outlines do not affect layout. That makes them good for hover or focus highlights, because nothing jumps. They can overlap neighbors and be clipped by an ancestor with overflow: hidden.
  • Outlines follow the border shape in modern browsers. With border-radius, current browsers curve the outline to match; older ones drew a rectangle.
  • Windows High Contrast / forced colors mode keeps outlines visible, while shadows are removed. Prefer an outline for focus rings over box-shadow.
  • Not per-side. Unlike borders there is no outline-top. Use a border or a shadow if you need a single side.

Browser support

Supported in every browser. Outline curving along border-radius is a fairly recent behavior, so check a compatibility table if you need it in older browsers.