outline-offset
Example
.gallery {
overflow: hidden;
}
.gallery a:focus-visible {
outline: 2px solid;
}.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-offsetto change layout or spacing around the element.
Key points
- Focus rings use a positive
outline-offsetso they don't touch the element's edge. - Elements inside
overflow: hiddenparents use a negativeoutline-offsetso 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.