CSS propertyBox model

outline

Draws an outline around an element that doesn’t take up space in the layout.

Initial value
medium none auto
Inherited
No
Animatable
yes, width and color
Applies to
all elements
JavaScript
element.style.outline = "2px solid #a78bfa"
On this page

Example

#
CSS
.button:focus-visible {
  outline: 2px solid #a78bfa;
  outline-offset: 3px;
}
Preview

Definition and usage

#

The outline property is shorthand for outline-width, outline-style, and outline-color. An outline looks similar to a border, but it’s drawn outside the element and doesn’t affect its size or position.

Browsers use it to show keyboard focus. That’s how people navigating with Tab can see where they are. Removing it with no replacement (outline: none) is one of the most common accessibility mistakes.

You can push the outline away from the element with outline-offset. Modern browsers also draw the outline following the element’s border-radius.

Syntax

#
Syntax
outline: <width> || <style> || <color>;

Values

#

Values in practice

#

none

No outline.
.demo { outline: none; }

2px solid #a78bfa

A purple outline right at the element’s edge.
.demo { outline: 2px solid #a78bfa; }

+ outline-offset

An outline pushed 4px away from the edge.
.demo { outline: 2px solid #a78bfa; outline-offset: 4px; }

3px dashed #f59e0b

A dashed outline.
.demo { outline: 3px dashed #f59e0b; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Instead of removing the outline, use :focus-visible. It only appears for keyboard navigation, not after a mouse click.
  • An outline doesn’t change the layout, so it’s great for highlighting elements while debugging.

Related entries

#

Spotted a mistake or missing an example? Write to us.