CSS outline-offset Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Borders & Focus

What You’ll Learn

The outline-offset property controls the gap between an element and its outline. It is especially helpful for cleaner focus rings and clearer visual separation.

01

Outline Gap

Space from the edge.

02

Length Values

px, em, rem.

03

Default 0

No gap by default.

04

Focus Rings

Keyboard highlight.

05

Negative Values

Pull outline inward.

06

Outline Set

Works with outline.

Introduction

The outline-offset property in CSS allows you to specify the space between an element’s outline and its border or edge.

This property is particularly useful when you want to create a clear visual distinction between the outline and the content of an element, enhancing the element’s focus style or visual appearance.

Definition and Usage

Use a positive offset to push the outline outward and create breathing room. This is common for buttons, links, and form controls that need a visible keyboard focus ring.

You must already have a visible outline before outline-offset has any effect.

💡
Beginner Tip

Compare outline-offset: 0; with outline-offset: 5px; on the same button to see the gap appear instantly.

📝 Syntax

The syntax for the outline-offset property is simple. You can define it with a length value that determines the distance between the outline and the element’s edge.

syntax.css
element {
  outline-offset: <length>;
}

Here, the value is a length such as pixels (px), em units (em), or any other valid CSS length unit.

Basic Example

outline-offset.css
button {
  outline: 2px solid blue;
  outline-offset: 5px;
}

Syntax Rules

  • Accepts length values such as px, em, and rem.
  • Positive values move the outline away from the element edge.
  • Negative values can move the outline inward in supporting browsers.
  • Requires a visible outline set with outline or its longhand properties.

🎯 Default Value

The default value of the outline-offset property is 0, meaning the outline is directly adjacent to the element’s border or edge.

Increase the value when you want visible space between the element and its focus ring.

⚡ Quick Reference

QuestionAnswer
Initial value0
Applies toAll elements
InheritedNo
AnimatableNo
Common useFocus ring spacing and visual emphasis

💎 Property Values

ValueExampleDescription
Lengthoutline-offset: 5px;Defines the space between the outline and the element edge
Positive lengthoutline-offset: 10px;Pushes the outline outward from the element
Negative lengthoutline-offset: -3px;Can pull the outline inward toward the element
Relative unitoutline-offset: 0.25em;Scales offset with the element’s font size
0 — default 2px — subtle gap 5px — clear gap -2px — inward

👀 Live Preview

Same outline, different offset values:

offset: 0 offset: 5px

Example Usage

Apply positive offsets for focus rings, compare spacing, and try negative values.

🔲 Basic Offset

Create space between a button border and its outline.

Example 1 — Button with 5px Outline Offset

In this example, we apply an outline to a button element and use the outline-offset property to create space between the outline and the button’s border.

button-offset.html
<style>
  button {
    outline: 2px solid blue;
    outline-offset: 5px;
  }
</style>

<button>Click Me!</button>
Try It Yourself

How It Works

The blue outline is offset by 5 pixels from the button’s border, creating a visible gap.

Example 2 — Keyboard Focus with Offset

Add space to a focus ring so it does not sit directly on the element edge.

focus-offset.css
a:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
}
Try It Yourself

How It Works

The offset makes the focus ring easier to notice against borders and backgrounds.

📐 Offset Variations

Try negative offsets and larger spacing on cards.

Example 3 — Negative Outline Offset

Pull the outline slightly inward with a negative length value.

negative-offset.css
.badge {
  outline: 2px solid #9333ea;
  outline-offset: -3px;
}
Try It Yourself

How It Works

Negative offsets move the outline closer to or inside the element edge depending on browser rendering.

Example 4 — Card with Larger Offset

Use a bigger offset to create a soft halo around a highlighted card.

card-offset.css
.card--selected {
  outline: 2px solid #16a34a;
  outline-offset: 8px;
}
Try It Yourself

How It Works

Larger offsets create a more open, halo-like selection effect around the card.

Works with the outline properties

outline-offset does not create an outline by itself. Combine it with outline, outline-width, outline-style, and outline-color.

outline-set.css
button:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 4px;
}

♿ Accessibility

  • Improve focus visibility — A small positive offset can make focus rings easier to see.
  • Do not remove focus styles — Offset spacing should enhance focus, not replace it.
  • Maintain contrast — Ensure the outline color still stands out after adding offset.
  • Test keyboard navigation — Verify the ring remains visible on all interactive elements.

🧠 How outline-offset Works

1

An outline is drawn

The browser renders an outline outside the element border box.

Outline
2

Offset shifts the ring

outline-offset adds space between the edge and the outline.

Length
3

Layout stays unchanged

Neither the outline nor the offset affects surrounding element positions.

No shift
=

Clearer visual separation

The outline becomes easier to read without moving page content.

Browser Compatibility

The outline-offset property is widely supported in modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. Test your design across browsers to ensure consistent behavior.

Baseline · Modern browsers

Strong support in current browsers

outline-offset works reliably for focus and emphasis styling in up-to-date browsers.

97% Modern browser support
Google Chrome 1+ · All versions
Full support
Mozilla Firefox 1.5+ · All versions
Full support
Apple Safari 1.2+ · macOS & iOS
Full support
Microsoft Edge 15+ · Modern versions
Full support
Opera 15+ · Modern versions
Full support
outline-offset property 97% supported

Bottom line: Safe to use for focus rings and outline spacing in modern projects.

Conclusion

The outline-offset property is a versatile tool that allows you to control the spacing between an element’s outline and its edge, enhancing the visual clarity and focus styles on your web page.

By experimenting with different offset values, you can create unique and visually appealing designs that improve the user experience.

💡 Best Practices

✅ Do

  • Use small positive offsets for focus rings (2px–4px)
  • Pair with a visible outline declaration
  • Test offset on buttons, links, and inputs
  • Use :focus-visible for keyboard-friendly focus
  • Keep contrast strong after adding spacing

❌ Don’t

  • Expect offset to work without an outline
  • Remove focus outlines and rely on offset alone
  • Use huge offsets that clip outside containers unexpectedly
  • Assume negative offsets look identical in every browser
  • Confuse outline offset with margin or padding

Key Takeaways

Knowledge Unlocked

Five things to remember about outline-offset

Use these points when spacing outlines away from elements.

5
Core concepts
02

Default 0

No spacing.

Default
📝 03

Length Values

px, em, rem.

Values
04

Focus Rings

Common use case.

Use case
🔲 05

Needs Outline

Not standalone.

Companion

❓ Frequently Asked Questions

outline-offset sets the space between an element's outline and its border or edge.
The default value is 0, which means the outline sits directly against the element edge.
Yes. Negative values can pull the outline inward toward the element in supporting browsers.
Yes. outline-offset only affects a visible outline created with outline, outline-width, and outline-style.
It creates breathing room between the element and the focus ring, making keyboard focus easier to see.

Practice in the Live Editor

Open the HTML editor and experiment with different outline-offset values on buttons and links.

HTML Editor →

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.

5 people found this page helpful