liveBook · Manning

Outline-offset

As explained in Tiny CSS Projects

The CSS outline-offset property specifies the distance between an element's outline and its border edge.

outline-offset sets the distance between an element’s outline and its edge. Positive lengths move the outline outward; negative lengths move it inward. section 8.2.2 section 11.5.1

Use outline-offset to make interactive states clearer or to fit an outline inside a control:

  • Add breathing room around a dotted hover outline with outline-offset: 2px. section 8.2.2
  • Keep keyboard focus visible with a solid outline and the same 2-pixel outward offset. section 8.2.2
  • Inset a share-button outline by 5 pixels with outline-offset: -5px. section 11.5.1

Hover and focus states

A button can use a dotted teal outline on hover and a solid teal outline on focus, with outline-offset: 2px in both states. A share button instead uses :focus-visible and outline-offset: -5px to place its black outline inside the button. section 8.2.2 section 11.5.1

Listing 8.4 Button hover and focus states
button:hover,
.button:hover {
  outline: dotted 1px #2c6c69;
  outline-offset: 2px;
}
 
button:focus,
.button:focus {
  outline: solid 1px #2c6c69;
  outline-offset: 2px;
}

Inspect the complete button hover and focus declarations, including outline style, width, color, and a 2-pixel offset. section 8.2.2

Listing 11.4 Share button hover and focus CSS
.share__button:hover,
.share__button:focus-visible {
  cursor: pointer;
  outline: solid 1px black;
  outline-offset: -5px;
}

Inspect a compact focus-visible example that offsets the outline inward by 5 pixels. section 11.5.1

How Tiny CSS Projects covers it

How deep it goes
Defines length-based outward and inward placement and demonstrates it in two button-state implementations.
Examples
Uses checkout buttons with 2-pixel outward offsets and a share button with a 5-pixel inward offset.
What it assumes
Assumes CSS selectors and pseudo-classes while explaining outline style, width, color, and length values in context.
What you can do after
Apply it via CSS to position hover and focus outlines outside or inside interactive elements.
How it connects
Connects CSS outlines with borders, :hover, :focus, :focus-visible, buttons, links, and keyboard accessibility.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.