outline-offset

Term side of the Card.
Topic: Borders, Outlines & Shadows
Unit title: outline-offset
Categories: Property
Explanation side of the Card

Explanation: The property that sets the space between the outline and the edge of the element's border box. It controls how far the outline is drawn from the element.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 15.
  • The firefox browser supports this feature starting from version 1.5.
  • The safari browser supports this feature starting from version 1.2.
Availability: 

Example

Wrongcss
.gallery {
  overflow: hidden;
}
.gallery a:focus-visible {
  outline: 2px solid;
}
Rightcss
.gallery {
  overflow: hidden;
}
.gallery a:focus-visible {
  outline: 2px solid;
  outline-offset: -2px;
}

A negative offset draws the ring inside the link, so the parent's overflow: hidden no longer cuts it off.

Common mistakes

  • The focus ring is cut off by a parent with overflow: hidden.
  • Expecting outline-offset to change layout or spacing around the element.

Key points

  • Focus rings use a positive outline-offset so they don't touch the element's edge.
  • Elements inside overflow: hidden parents use a negative outline-offset so the ring isn't clipped.

Interview questions

Can outline-offset be negative?

Yes. A negative value draws the outline inside the element's border box.

Does outline-offset affect layout?

No. Outlines and their offset never change the size or position of any element.

What is the default outline-offset?

'0', so the outline is drawn right at the edge of the border box.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy