Home CSS Properties outline-offset CSS outline-offset Property Definition
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.
Syntax
CSS Syntax outline-offset: <length> | initial | inherit ;
Example: outline-offset: 4px; Percentages are not valid — use a length such as px, em, or rem.
Values
Property Values Value Description Try it 0Default. Outline sits on the border edge Try itPositive <length> Moves the outline outward (for example 4px) Try itNegative <length> Moves the outline inward into the element Try itinitialResets to 0 Try itinheritUses the parent’s outline-offset Try it
Approach
How to Use outline-offset Draw an outline first, then add the gap you want between the border and the ring.
Set a visible outline with outline or style/width/color longhands. Add outline-offset with a length (4px, 0.25em, …). For focus UI, apply both under :focus or :focus-visible . Keep enough space so the ring stays clear of text and icons. Piece Required? Role Visible outline Yes Offset has nothing to move without a style <length>Yes Distance from the border edge Border (optional) Helpful Makes the gap easier to see while learning Not in shorthand — Always declare outline-offset separately
Try it
Live Preview Outline width, style, and color stay fixed. Change only outline-offset.
Code
CSS Examples Each snippet draws an outline first, then sets only the offset you are studying. Use Try It Yourself for a live editor.
1. Positive gap 2. Negative offset 3. Focus ring Example 1 — Positive Gap Push the outline 8px away from the border.
<style>
div {
outline: 3px solid #2563eb;
outline-offset: 8px;
border: 1px solid #cbd5e1;
padding: 12px;
}
</style>
<div>8px gap</div> How It Works Draw the outline. outline: 3px solid #2563eb creates a visible ring.Add space. outline-offset: 8px moves that ring outward.Border stays put. The gray border marks the box edge for comparison.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.
<style>
div {
outline: 3px solid #2563eb;
outline-offset: -6px;
border: 1px solid #cbd5e1;
padding: 16px;
}
</style>
<div>Inset outline</div> How It Works Same outline setup as Example 1.Use a negative length. -6px draws the ring inside the padding box.Give padding room. Extra padding keeps text from sitting under the inset ring.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.
<style>
button {
outline: none;
}
button:focus {
outline: 3px solid #d97706;
outline-offset: 4px;
}
</style>
<button type="button">Tab to focus</button> Tab to focus Click or Tab to the button to see the offset focus ring.
How It Works Replace the default ring only if you draw a new one on focus.Set outline on :focus. Style, width, and color appear together.Add outline-offset: 4px. The ring lifts off the button edge for clearer focus.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.
Compatibility
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.
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.
Remember
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 What does the CSS outline-offset property do? It sets the space between an element’s outline and its border edge. Positive values push the outline outward. Negative values pull it inward.
What is the default value of outline-offset? The initial value is 0, so the outline sits against the border edge with no gap.
Is outline-offset part of the outline shorthand? No. The outline shorthand covers width, style, and color only. Set outline-offset on its own.
Do I need a visible outline first? Yes. Without outline-style (or a shorthand that includes a style), there is no outline to offset.
Is outline-offset inherited? No. The gap does not affect layout. The space between the element and the outline is transparent and shows the parent background.
Which browsers support outline-offset? It is Baseline Widely available in modern Chrome, Firefox, Safari, and Edge. It is a browser CSS property, not a Node.js feature.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion