CSS outline Property

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

What You’ll Learn

The outline property draws a highlight around an element without changing its size or pushing other content. It is especially useful for focus states and accessibility.

01

Highlight Ring

Draw around elements.

02

Shorthand

Width, style, color.

03

No Layout Shift

Unlike borders.

04

Focus Styles

Keyboard navigation.

05

Longhand Props

Split into parts.

06

outline-offset

Move outline outward.

Introduction

The outline property in CSS is used to create an outline around elements. This outline is similar to a border but has some key differences, such as not affecting the layout or taking up space.

It’s often used to highlight elements, such as when a user interacts with form controls or navigates a page using the keyboard.

Definition and Usage

Use outline when you want a visible ring around an element without changing its width, height, or the position of nearby content.

For decorative boxes that should affect layout, use border instead. For keyboard focus indicators, outline is usually the better choice.

💡
Beginner Tip

Try outline: 3px solid #2563eb; on a button, then compare it with border: 3px solid #2563eb; to see how borders change layout but outlines do not.

📝 Syntax

The outline property is a shorthand property for setting the following individual outline properties: outline-color, outline-style, and outline-width.

syntax.css
element {
  outline: [outline-width] [outline-style] [outline-color];
}

Basic Example

outline.css
button {
  outline: 3px solid red;
}

Syntax Rules

  • You can omit parts of the shorthand; omitted values reset to their defaults.
  • outline-style: none hides the outline even if width or color is set.
  • Outlines are drawn outside the border edge and do not affect box dimensions.
  • Use longhand properties when you need to change only one part of the outline.

🎯 Default Value

The default value of the outline property is equivalent to medium none currentColor. This means that if no values are specified, the outline will not be visible.

Browsers may show a default focus outline on interactive elements until you style focus states yourself.

⚡ Quick Reference

QuestionAnswer
Initial valuemedium none currentColor
Applies toAll elements
InheritedNo
AnimatablePartially (color and width in some browsers)
Common useFocus indicators and non-layout highlights

💎 Property Values

PartExampleDescription
outline-width2px, thin, thickDefines the thickness of the outline
outline-stylesolid, dashed, dottedSpecifies the line style of the outline
outline-colorred, #2563eb, currentColorSets the color of the outline
solid — continuous line dashed — broken line dotted — dotted line none — hidden

👀 Live Preview

A button with outline: 3px solid #2563eb and common outline styles:

Outlined Button

Examples Gallery

From shorthand button outlines to longhand input styles and accessible focus rings.

🔲 Basic Outlines

Use the shorthand or longhand outline properties.

Example 1 — Button with Solid Outline

In this example, we apply a solid outline around a button with a thickness of 3px and a color of red.

button-outline.html
<style>
  button {
    outline: 3px solid red;
  }
</style>

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

How It Works

The outline appears around the button without changing its size in the layout.

Example 2 — Using Outline Properties on an Input

In this example, we use individual outline properties to create a dashed outline around an input field.

input-outline.html
<style>
  input[type="text"] {
    outline-width: 2px;
    outline-style: dashed;
    outline-color: blue;
  }
</style>

<input type="text" placeholder="Type here">
Try It Yourself

How It Works

Longhand properties combine to produce the same result as a single shorthand declaration.

♿ Focus & Comparison

Use outlines for keyboard focus and compare them with borders.

Example 3 — Accessible Focus Outline

Show a clear focus ring when users tab to a link or button.

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

How It Works

:focus-visible shows the outline for keyboard users while avoiding unnecessary rings on mouse clicks in supporting browsers.

Example 4 — Outline vs Border

See why borders change layout but outlines do not.

outline-vs-border.css
.with-border {
  border: 3px solid #9333ea;
}

.with-outline {
  outline: 3px solid #9333ea;
}
Try It Yourself

How It Works

The border adds to the element’s box size. The outline is drawn outside without shifting siblings.

Longhand properties and outline-offset

Split the shorthand into outline-width, outline-style, and outline-color when you need finer control. Use outline-offset to push the outline farther away from the element.

outline-longhand.css
.card:focus-visible {
  outline-width: 2px;
  outline-style: solid;
  outline-color: #2563eb;
  outline-offset: 4px;
}

♿ Accessibility

  • Keep visible focus — Do not remove focus outlines without providing a clear replacement.
  • Use :focus-visible — Show strong outlines for keyboard users when possible.
  • Ensure contrast — Focus rings should stand out against the background.
  • Prefer outline over border for focus — Outlines avoid layout jumps when focus changes.

🧠 How outline Works

1

You set width, style, and color

The shorthand combines the three outline longhand properties.

Shorthand
2

The browser draws outside the border

The outline sits beyond the border edge and does not change box dimensions.

Layout
3

Optional offset adds spacing

outline-offset can move the ring farther from the element.

Offset
=

Clear highlight without layout shift

Elements gain a visible ring while nearby content stays in place.

Browser Compatibility

The outline property is widely supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is also well supported in older browsers, making it a reliable choice for styling.

Baseline · Universal support

Excellent support everywhere

outline has long been supported and works reliably for focus and highlight styles.

99% Global 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 12+ · All versions
Full support
Opera 7+ · All versions
Full support
outline property 99% supported

Bottom line: outline is one of the safest properties for focus and highlight styling.

Conclusion

The outline property is a versatile tool for adding visual emphasis to elements on a webpage. It provides a simple way to enhance accessibility and highlight interactive elements without affecting the layout.

By adjusting the outline’s width, style, and color, you can create various visual effects that improve the user experience on your site.

💡 Best Practices

✅ Do

  • Use outline for keyboard focus indicators
  • Pair with outline-offset for clearer rings
  • Prefer :focus-visible for modern focus behavior
  • Use longhand properties when changing one value only
  • Choose high-contrast outline colors

❌ Don’t

  • Remove focus outlines without a replacement
  • Use outline when you need layout-affecting decoration
  • Confuse outline with border for box sizing
  • Assume all outline styles render identically everywhere
  • Rely on outline alone for complex component shapes

Key Takeaways

Knowledge Unlocked

Five things to remember about outline

Use these points when highlighting elements without layout shifts.

5
Core concepts
02

Shorthand

Width, style, color.

Syntax
📝 03

Longhand Split

Three sub-properties.

Values
04

Focus Rings

Keyboard highlight.

Use case
💻 05

Universal Support

Works everywhere.

Support

❓ Frequently Asked Questions

outline draws a line around an element without taking up layout space. It is commonly used for focus indicators and visual emphasis.
A border affects layout and box size, while an outline is drawn outside the border box and does not shift surrounding content.
The default is medium none currentColor, which means no visible outline unless you set style, width, or color.
Yes. outline is widely used with :focus or :focus-visible to show which element is active without changing layout.
The outline shorthand sets outline-width, outline-style, and outline-color in one declaration.

Practice in the Live Editor

Open the HTML editor and experiment with outline shorthand, longhand properties, and focus styles.

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