CSS outline-offset Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The outline-offset property sets how far an outline sits from the element’s border edge. A positive length pushes the ring outward. A negative length pulls it inward. The gap is transparent, so the parent background shows through.

It is not part of the outline shorthand. You still need a visible outline (outline-style plus width/color). The initial value is 0. It does not change layout size.

Baseline · Widely available.

Not deprecated and not experimental. Safe for focus rings in modern browsers. Always keep a visible focus style when customizing outlines.

CSS Syntax

syntax.css
outline-offset: <length> | initial | inherit;

Example: outline-offset: 4px; Percentages are not valid — use a length such as px, em, or rem.

Property Values

ValueDescriptionTry it
0Default. Outline sits on the border edgeTry it
Positive <length>Moves the outline outward (for example 4px)Try it
Negative <length>Moves the outline inward into the elementTry it
initialResets to 0Try it
inheritUses the parent’s outline-offsetTry it

How to Use outline-offset

Draw an outline first, then add the gap you want between the border and the ring.

  1. Set a visible outline with outline or style/width/color longhands.
  2. Add outline-offset with a length (4px, 0.25em, …).
  3. For focus UI, apply both under :focus or :focus-visible.
  4. Keep enough space so the ring stays clear of text and icons.
PieceRequired?Role
Visible outlineYesOffset has nothing to move without a style
<length>YesDistance from the border edge
Border (optional)HelpfulMakes the gap easier to see while learning
Not in shorthand—Always declare outline-offset separately

Live Preview

Outline width, style, and color stay fixed. Change only outline-offset.

Gray = border. Blue = outline. The gap between them is the offset.

Box

outline-offset: 4px

CSS Examples

Each snippet draws an outline first, then sets only the offset you are studying. Use Try It Yourself for a live editor.

Example 1 — Positive Gap

Push the outline 8px away from the border.

CSS
<style>
  div {
    outline: 3px solid #2563eb;
    outline-offset: 8px;
    border: 1px solid #cbd5e1;
    padding: 12px;
  }
</style>

<div>8px gap</div>
Try It Yourself

How It Works

  1. Draw the outline. outline: 3px solid #2563eb creates a visible ring.
  2. Add space. outline-offset: 8px moves that ring outward.
  3. Border stays put. The gray border marks the box edge for comparison.
  4. Gap is empty. The space between border and outline shows the page background.

Example 2 — Negative Offset

Pull the outline inside the element with a negative length.

CSS
<style>
  div {
    outline: 3px solid #2563eb;
    outline-offset: -6px;
    border: 1px solid #cbd5e1;
    padding: 16px;
  }
</style>

<div>Inset outline</div>
Try It Yourself

How It Works

  1. Same outline setup as Example 1.
  2. Use a negative length. -6px draws the ring inside the padding box.
  3. Give padding room. Extra padding keeps text from sitting under the inset ring.
  4. Still no layout change. Neighbors do not move when the outline slides inward.

Example 3 — Focus Ring Offset

Add breathing room to a keyboard focus outline.

CSS
<style>
  button {
    outline: none;
  }
  button:focus {
    outline: 3px solid #d97706;
    outline-offset: 4px;
  }
</style>

<button type="button">Tab to focus</button>
Try It Yourself

How It Works

  1. Replace the default ring only if you draw a new one on focus.
  2. Set outline on :focus. Style, width, and color appear together.
  3. Add outline-offset: 4px. The ring lifts off the button edge for clearer focus.
  4. Prefer :focus-visible in real UIs when you want the ring mainly for keyboard users.

Edge Cases & Pitfalls

If the gap never appears, check these first.

style

No outline, no offset

With outline-style: none, offset has nothing to move. Set a style first (or use the outline shorthand).

shorthand

Not included in outline

Resetting with outline: … does not clear or set offset. Declare outline-offset separately every time you need it.

%

Percentages are invalid

Use lengths only (px, em, rem). A value like 10% is not valid for this property.

overlap

Large offsets can cover neighbors

Outlines still paint outside the box model. A big positive offset may sit on nearby content — leave margin if needed.

a11y

Keep focus rings visible

Offset improves clarity, but never remove focus outlines without a replacement that meets contrast needs.

Browser Support

outline-offset is a browser CSS property for outline spacing. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

outline-offset

Supported in modern Chrome, Firefox, Safari, and Edge. Safe for production focus styles.

98% Global support
Google Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Opera All modern versions
Full support
Samsung Internet Supported
Full support
Internet Explorer No support
No support
outline-offset Widely supported

Bottom line: Use freely in modern browsers for focus rings and emphasis. This is not a JavaScript runtime API.

Key Takeaways

  • Role: set the gap between the outline and the border edge.
  • Initial: 0. Positive out, negative in. Lengths only.
  • Separate property: not included in the outline shorthand.
  • Focus: a small positive offset often makes keyboard rings clearer.

One line: outline-offset slides the outline in or out — without changing the box size.

Frequently Asked Questions

It sets the space between an element’s outline and its border edge. Positive values push the outline outward. Negative values pull it inward.
The initial value is 0, so the outline sits against the border edge with no gap.
No. The outline shorthand covers width, style, and color only. Set outline-offset on its own.
Yes. Without outline-style (or a shorthand that includes a style), there is no outline to offset.
No. The gap does not affect layout. The space between the element and the outline is transparent and shows the parent background.
It is Baseline Widely available in modern Chrome, Firefox, Safari, and Edge. It is a browser CSS property, not a Node.js feature.

Next: outline-style

Choose solid, dashed, dotted, and other outline patterns.

outline-style tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful