CSS outline Property

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

Definition and Usage

The outline property is a shorthand for outline-width, outline-style, and outline-color. It draws a line outside the border edge and does not take layout space.

Use it for focus rings and emphasis. Unlike border, changing the outline will not push neighbors. Gap from the border is controlled separately with outline-offset.

Baseline · Widely available.

Not deprecated. Do not remove default focus outlines without a clear replacement. The old invert outline color is not supported in modern browsers.

CSS Syntax

syntax.css
outline: <outline-width> || <outline-style> || <outline-color>;

Example: outline: 3px solid #2563eb;. Order of the three parts does not matter. Omit any part to use its initial value.

Property Values

ValueDescriptionTry it
<outline-style>Required to see a line. Default is noneTry it
<outline-width>Thickness: length, or thin / medium / thickTry it
<outline-color>Any CSS color (or auto). Defaults to current text color in practiceTry it
noneNo outline. Also used carefully on focus — replace it if removedTry it
initial / inheritReset to defaults, or copy from the parentTry it

How to Use outline

Pick a style first, then width and color. Add offset when you want space from the border.

  1. Choose at least an outline-style (solid, dashed, …).
  2. Add width and color in the same shorthand, or leave defaults.
  3. For focus, style :focus or :focus-visible — never remove the ring without a replacement.
  4. Use outline-offset to pull the ring away from the edge.
PieceRequired?Role
StyleYes (to see it)Without a style, most outlines stay invisible
WidthOptionalDefaults to medium
ColorOptionalUsually falls back to currentColor
outline-offsetOptionalNot part of the shorthand — set separately

Live Preview

Change the full outline shorthand on a sample box. The thin gray border is the element edge; the outline sits outside it.

Layout stays the same when the outline changes — neighbors do not shift.

Box

outline: 3px solid #2563eb

CSS Examples

Each snippet focuses on the outline shorthand. Extra styles stay minimal. Use Try It Yourself for a live editor.

Example 1 — Solid Outline

Draw a blue outline outside a box without changing its size.

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

<div>Outlined box</div>
Try It Yourself

How It Works

  1. Set the shorthand. 3px is width, solid is style, #2563eb is color.
  2. Style is required. Without solid, the default none would hide the outline.
  3. Border stays separate. The gray border shows the box edge; the outline sits outside it.
  4. No layout shift. Padding and size stay the same when the outline appears.

Example 2 — Focus Ring

Show a clear keyboard focus style with outline and offset.

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

<a href="#">Tab to focus me</a>
Try It Yourself

How It Works

  1. Replace, don’t erase. Resting state can clear the default ring only if :focus draws a new one.
  2. Dashed orange ring. outline: 3px dashed #d97706 is easy to see on focus.
  3. Add space. outline-offset: 4px lifts the ring off the text edge.
  4. Prefer :focus-visible in real UIs so mouse clicks need not show the same ring.

Example 3 — Outline vs Border

Compare a thick border (affects size) with a thick outline (does not).

CSS
<style>
  .with-border {
    border: 6px solid #2563eb;
    padding: 12px;
  }
  .with-outline {
    outline: 6px solid #2563eb;
    border: 1px solid #cbd5e1;
    padding: 12px;
  }
</style>

<div class="with-border">Border grows the box</div>
<div class="with-outline">Outline does not</div>
Try It Yourself

How It Works

  1. Border is inside the box model. A 6px border adds to the element’s outer size (unless you use box-sizing: border-box carefully).
  2. Outline paints outside. The second box keeps the same content size; the ring overlaps nearby space.
  3. Same visual weight, different job. Use border for structure; use outline for focus and temporary emphasis.
  4. Corners. Modern browsers often follow border-radius for outlines too.

Edge Cases & Pitfalls

If the outline is missing or focus looks broken, check these first.

a11y

Never drop focus without a replacement

outline: none on interactive controls must come with a visible :focus / :focus-visible style (WCAG focus visible).

style

No style means no outline

Initial outline-style is none. Width and color alone usually will not show a line.

offset

outline-offset is not in the shorthand

Set outline-offset on its own. The shorthand only covers width, style, and color.

invert

invert is obsolete in practice

Modern browsers do not support outline-color: invert. Use an explicit color or currentColor.

space

Outlines can overlap neighbors

Because they sit outside the box, thick outlines may paint over nearby content. Add offset or spacing if needed.

Browser Support

outline is a browser CSS property for visual rings and focus indicators. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

outline

Supported across modern browsers for decades (Chrome, Firefox, Safari, Edge, IE 8+). Safe for production focus styles.

99% 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 8+
Full support
outline Widely supported

Bottom line: Use freely for focus indicators. Do not rely on invert. This is not a JavaScript runtime API.

Key Takeaways

  • Role: shorthand for width, style, and color of a non-layout ring outside the border.
  • Style first: without a style other than none, you usually see nothing.
  • Not border: outline does not change the box size; border can.
  • Focus: keep a visible indicator — replace the default ring, don’t delete it.

One line: outline paints a freestanding ring for emphasis and focus — style it, don’t silence it.

Frequently Asked Questions

It is a shorthand for outline-width, outline-style, and outline-color. It draws a line around an element outside the border and does not take up layout space.
A border is part of the box model and can change size and layout. An outline sits outside the border box, does not affect layout, and is often used for focus rings.
outline-style defaults to none. You must set a style such as solid, or the outline will not show for most elements.
No. Setting outline: none or 0 without a replacement fails keyboard focus visibility. Provide a clear :focus or :focus-visible style instead.
No. The shorthand’s initial values are medium, none, and auto/currentColor for color. Set it on each element that needs an outline.
It is Baseline Widely available in all modern browsers. It is a browser CSS property, not a Node.js feature. The old invert outline color is not supported in current browsers.

Next: outline-color

Set only the color of an element’s outline.

outline-color 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