CSS Portal

CSS outline Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The outline property draws a line around an element, outside the element's border edge, to visually emphasize or separate it from surrounding content. Unlike borders, outlines are not part of the CSS box model: they do not occupy layout space and therefore do not affect the element's size or cause reflow when added or removed. Because outlines are painted outside the box, they can overlap adjacent elements and are typically used for temporary or overlay-style highlighting rather than defining an element's structural appearance.

Visually and behaviorally, an outline differs from a border in several important ways. A border is part of the element's box and follows the box's shape and rounding, while an outline is independent of box sizing and can be rendered outside rounded corners or over neighboring content. For quick comparisons or replacements, developers sometimes choose a border for a permanent decorative edge and an outline for transient emphasis; see border for more about the border concept and how it participates in layout.

Outlines are commonly used for accessibility and interaction feedback, most notably as keyboard focus indicators that help users navigate pages without a pointing device. Because they do not change layout, outlines are ideal for focus rings that must appear and disappear without shifting nearby content. When you want to move an outline away from the element edge without affecting size, the outline-offset property is used to shift its position, while visual effects that simulate or extend an outline (such as soft glows or multiple layered strokes) are frequently implemented with box-shadow instead — box shadows offer blur and spread control and integrate differently with stacking and clipping.

Practical considerations: removing an outline entirely can harm keyboard users unless a clear, accessible alternative focus indicator is provided. Because outlines can overlap other elements, they may interact with overflow and stacking contexts in ways that differ from borders or shadows; plan their use accordingly when designing dense or interactive interfaces. For transient debugging (quickly spotting layout issues) and for emphasizing interactive states (hover, focus, active), outlines are a lightweight, non-disruptive tool that complements rather than replaces more permanent visual styles.

Definition

Initial value
Based on individual properties
Applies to
All elements
Inherited
No
Computed value
See individual properties
Animatable
No
JavaScript syntax
object.style.outline

Interactive Demo

The rusty swing set creaked a lonely lullaby in the twilight, shadows lengthening like grasping fingers across the dew-kissed grass. A lone dandelion seed, adrift on the breeze, whispered secrets of faraway fields, of dandelion suns and galaxies spun from fluff.

Syntax

outline: [ <outline-color> || <outline-style> || <outline-width> ] | inherit 

Values

  • <outline-color>See the outline-color CSS property for values.
  • <outline-style>See the outline-style CSS property for values.
  • <outline-width>See the outline-width CSS property for values.
  • inherit

Example

<div class="example">
<h2>Outline property examples</h2>
<button class="outline-default">Default outline on focus</button>
<button class="outline-custom">Custom dashed outline</button>
<button class="outline-offset">Outline with offset</button>
<div class="box outline-dashed" tabindex="0">Focusable box (tab to focus)</div>
<p>Try tabbing or hovering the elements to see outlines for accessibility.</p>
</div>
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f7fafc;
    color: #1a202c;
    padding: 32px;
}

.example {
    max-width: 720px;
    margin: 0 auto;
}

h2 {
    margin-bottom: 16px;
}

button {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    padding: 10px 16px;
    margin: 6px 8px 6px 0;
    background: #1e293b;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.box {
    margin-top: 16px;
    padding: 18px;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    display: inline-block;
    min-width: 220px;
    cursor: default;
}

/* Default solid outline */
button.outline-default:hover,
button.outline-default:focus {
    outline: 3px solid rgba(0,95,204,0.9);
    outline-offset: 0;
}

/* Dashed outline example */
button.outline-custom:hover,
button.outline-custom:focus {
    outline: 4px dashed #ff6b6b;
    outline-offset: 4px;
}

/* Outline with a larger offset */
button.outline-offset:hover,
button.outline-offset:focus {
    outline: 3px solid #2ecc71;
    outline-offset: 8px;
}

/* Focusable box with dashed outline */
.box.outline-dashed:hover,
.box.outline-dashed:focus {
    outline: 3px dashed #ffb400;
    outline-offset: 6px;
}

p {
    margin-top: 12px;
    color: #4a5568;
    font-size: 13px;
}

Browser Support

The following information will show you the current browser support for the CSS outline property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!