CSS outline-width Property

The CSS outline-width property specifies the thickness of an outline drawn around an element.

Outline thickness can be defined using the keywords thin, medium, and thick, or with a non-negative CSS length such as 3px. Outlines are commonly used for keyboard focus indicators and visual highlights. Unlike borders, they do not affect an element's layout dimensions.

outline-width Syntax

The outline-width property accepts a predefined width keyword or a non-negative CSS length.

Basic Syntax

selector {
  outline-width: 3px;
}

Keyword Values

.box {
  outline-width: thin;
}
.box {
  outline-width: medium;
}
.box {
  outline-width: thick;
}

Length Values

.box {
  outline-width: 2px;
}
.box {
  outline-width: 0.25rem;
}
.box {
  outline-width: 0.2em;
}

Zero Width

.box {
  outline-width: 0;
}

CSS-Wide Keywords

.box {
  outline-width: initial;
}
.box {
  outline-width: inherit;
}
.box {
  outline-width: unset;
}
.box {
  outline-width: revert;
}
.box {
  outline-width: revert-layer;
}

The initial value is medium. However, an outline is not normally displayed until an outline style other than none or hidden is applied.

Property Values

Value Description
thin Specifies a thin outline. The exact thickness is determined by the browser.
medium Specifies a medium outline. This is the initial value.
thick Specifies a thick outline. The exact thickness is determined by the browser.
<length> Specifies a non-negative outline thickness using a CSS length, such as 3px or 0.2rem.
0 Specifies zero outline thickness, preventing a visible outline.
initial Resets the property to medium.
inherit Uses the computed outline width of the parent element.
unset Resets the property to medium because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value medium
Inherited No
Applies to All elements
Computed value Absolute length, or 0 when the outline style is none or hidden
Animation type By computed value type
Affects layout No
Accepts negative values No
Related shorthand outline

Valid Values

.box {
  outline-width: thin;
}
.box {
  outline-width: medium;
}
.box {
  outline-width: thick;
}
.box {
  outline-width: 4px;
}
.box {
  outline-width: 0.25em;
}
.box {
  outline-width: calc(2px + 0.1rem);
}

Invalid Values

.box {
  outline-width: -3px;
}
.box {
  outline-width: 50%;
}
.box {
  outline-width: auto;
}
.box {
  outline-width: solid;
}

Negative lengths, percentages, auto, and outline style keywords are not valid outline-width values.

How It Works

The outline-width property controls how thick an outline appears. It works with outline-style and outline-color to determine the complete outline.

Setting an Outline Width

.box {
  outline-style: solid;
  outline-width: 4px;
  outline-color: #2563eb;
}

The element receives a four-pixel solid blue outline.

Changing Only the Width

.box {
  outline: 2px solid #2563eb;
}
.box.highlighted {
  outline-width: 6px;
}

The highlighted element keeps the same outline style and color but uses a thicker outline.

Width Without a Visible Style

.box {
  outline-width: 5px;
}

No outline normally appears because the initial outline-style value is none.

Outline Width and Layout

Increasing outline thickness does not increase the element's box dimensions. The outline is drawn without taking up layout space and may overlap nearby content.

Important Consideration

The outline must have a visible style and color for its thickness to be apparent. An outline with zero width is not visible.

Keyword Values

The thin, medium, and thick keywords provide predefined outline thicknesses.

thin

.box {
  outline: thin solid #2563eb;
}

Creates a relatively thin outline.

medium

.box {
  outline: medium solid #2563eb;
}

Creates a medium-width outline.

thick

.box {
  outline: thick solid #2563eb;
}

Creates a relatively thick outline.

Comparing Keywords

Keyword Relative Thickness
thin Thin
medium Medium
thick Thick

Important Consideration

The specification does not require particular pixel values for these keywords. Use explicit lengths when consistent thickness is important.

Length Values

Length values provide precise control over outline thickness. Common units include px, em, and rem.

Pixels

.box {
  outline: 3px solid #2563eb;
}

Pixels are useful for consistent interface styling.

em Units

.box {
  outline-style: solid;
  outline-width: 0.2em;
  outline-color: #2563eb;
}

The width is calculated relative to the element's font size.

rem Units

.box {
  outline-style: solid;
  outline-width: 0.2rem;
  outline-color: #2563eb;
}

The width is calculated relative to the root element's font size.

Calculated Width

.box {
  outline-style: solid;
  outline-width: calc(2px + 0.1rem);
  outline-color: #2563eb;
}

CSS Custom Properties

:root {
  --focus-outline-width: 3px;
}
button:focus-visible {
  outline-style: solid;
  outline-width: var(--focus-outline-width);
  outline-color: #2563eb;
}

Custom properties make it easier to maintain consistent outline thickness across interactive elements.

Invalid Percentage

.box {
  outline-width: 10%;
}

Percentage values are not supported.

Zero Width

Setting outline-width to 0 prevents the outline from being visible, even if its style and color are defined.

Basic Zero Width

.box {
  outline-style: solid;
  outline-width: 0;
  outline-color: #2563eb;
}

Resetting the Width

.box {
  outline: 4px solid #2563eb;
}
.box.no-outline {
  outline-width: 0;
}

The second rule removes the visible thickness of the outline.

Restoring a Visible Width

.box {
  outline-style: solid;
  outline-width: 0;
  outline-color: #2563eb;
}
.box.highlighted {
  outline-width: 4px;
}

The highlighted element displays a four-pixel outline.

Important Consideration

Do not use a zero-width outline to remove keyboard focus indicators unless another clearly visible focus indicator is provided.

Outline Width and Style

The appearance of an outline depends on both its width and style. Different styles can produce different visual results at the same thickness.

Solid Outline

.box {
  outline: 4px solid #2563eb;
}

Dashed Outline

.box {
  outline: 4px dashed #2563eb;
}

Dotted Outline

.box {
  outline: 4px dotted #2563eb;
}

Double Outline

.box {
  outline: 6px double #2563eb;
}

The double style divides the specified thickness between two lines and the space separating them.

Three-Dimensional Outline

.box {
  outline: 6px ridge #64748b;
}

Three-dimensional styles such as ridge and groove may require greater thickness to make their effects noticeable.

Important Consideration

Outline styles such as none and hidden prevent an outline from being drawn, regardless of the specified width.

Using the outline Shorthand

The outline shorthand combines the outline width, style, and color into a single declaration.

Shorthand Declaration

.box {
  outline: 4px solid #2563eb;
}

Equivalent Longhand Declarations

.box {
  outline-width: 4px;
  outline-style: solid;
  outline-color: #2563eb;
}

Both examples create the same outline.

Overriding the Width

.box {
  outline: 2px solid #2563eb;
  outline-width: 6px;
}

The later longhand declaration changes the outline thickness to six pixels.

Shorthand Reset Behavior

.box {
  outline-width: 8px;
  outline: solid #2563eb;
}

The shorthand resets outline-width to its initial value of medium because no width is included.

Using outline-offset

.box {
  outline: 4px solid #2563eb;
  outline-offset: 5px;
}

The outline-offset property is not part of the shorthand and must be declared separately.

Outline Width and Offset

The outline-width property controls thickness, while outline-offset controls the distance between the outline and the element's border edge.

Thick Outline Without Offset

.box {
  outline: 6px solid #2563eb;
  outline-offset: 0;
}

Thin Outline with Offset

.box {
  outline: 2px solid #2563eb;
  outline-offset: 6px;
}

Thick Outline with Offset

.box {
  outline: 6px solid #2563eb;
  outline-offset: 6px;
}

Negative Offset

.box {
  outline: 4px solid #2563eb;
  outline-offset: -5px;
}

A negative offset moves the outline inward, potentially overlapping the element's background or content.

Important Consideration

Increasing outline width or offset may cause the outline to overlap nearby content or become clipped by an ancestor container.

Outline Width vs. Border Width

Outlines and borders can both have a specified thickness, but they affect element layout differently.

Feature Outline Width Border Width
Affects box dimensions No Yes, depending on box sizing
Supports thin, medium, thick Yes Yes
Supports length values Yes Yes
Individual side widths No Yes
Can use outline-offset Yes No
Common use Focus indicators and highlights Element boundaries and decoration

Border Width

.box {
  border: 4px solid #2563eb;
}

Outline Width

.box {
  outline: 4px solid #2563eb;
}

The border contributes to the box model, while the outline does not.

Using Both

.box {
  border: 2px solid #64748b;
  outline: 4px solid #2563eb;
  outline-offset: 4px;
}

The border and outline can have different widths and colors without changing each other's properties.

Focus Indicators

Outline thickness is important for keyboard focus indicators because it helps users identify the currently focused element.

Button Focus Outline

button:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
}

Link Focus Outline

a:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 3px;
}

Form Control Focus Outline

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

Using Custom Properties

:root {
  --focus-outline-width: 3px;
  --focus-outline-color: #2563eb;
}
:focus-visible {
  outline-style: solid;
  outline-width: var(--focus-outline-width);
  outline-color: var(--focus-outline-color);
  outline-offset: 3px;
}

Custom properties make it easier to apply consistent focus styling throughout a website.

Important Consideration

Choose an outline width that is easy to see without obscuring nearby content. A thickness of two or three pixels is a common starting point, but the appropriate width depends on the design.

Accessibility Considerations

Visible focus indicators help keyboard users understand which element currently has focus. Outline thickness, color, and spacing all contribute to their visibility.

Avoid Zero-Width Focus Outlines

button:focus {
  outline-width: 0;
}

This removes the visible outline thickness and may make keyboard focus difficult to identify.

Provide a Visible Focus Indicator

button:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
}

Maintain Sufficient Contrast

A thick outline may still be difficult to see if its color blends into the surrounding background. Choose a color that remains clearly distinguishable.

Forced Colors Mode

@media (forced-colors: active) {
  :focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
}

System colors can help preserve focus visibility in forced-colors environments.

Avoid Clipped Focus Indicators

Thick outlines may extend beyond the element and become clipped by ancestor containers that restrict overflow.

Important Consideration

Test focus indicators with the Tab and Shift+Tab keys. Check that they remain visible on different backgrounds and at different zoom levels.

outline-width Example

This example compares several outline widths. Each box uses the same outline style and color so the differences in thickness are easy to see.

HTML Example

<div class="outline-width-demo">
  <div class="outline-box width-thin">Thin</div>
  <div class="outline-box width-medium">Medium</div>
  <div class="outline-box width-thick">Thick</div>
  <div class="outline-box width-custom">8px</div>
</div>

CSS Example

.outline-width-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 30px;
  padding: 24px;
  background-color: #f1f5f9;
}
.outline-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 70px;
  background-color: #fff;
  color: #334155;
  font-weight: 700;
  outline-style: solid;
  outline-color: #2563eb;
  outline-offset: 3px;
}
.width-thin {
  outline-width: thin;
}
.width-medium {
  outline-width: medium;
}
.width-thick {
  outline-width: thick;
}
.width-custom {
  outline-width: 8px;
}
Browser Result
Thin
Medium
Thick
8px

The keyword values use browser-defined thicknesses, while the custom value explicitly sets an eight-pixel outline. The boxes retain their original layout dimensions.

Interactive Focus Example

This example increases the outline width when a button receives visible keyboard focus.

<button class="outline-width-focus" type="button">Focus Me</button>
.outline-width-focus {
  padding: 12px 20px;
  border: 2px solid #2563eb;
  background-color: #fff;
  color: #1e40af;
  cursor: pointer;
}
.outline-width-focus:focus-visible {
  outline-style: solid;
  outline-width: 4px;
  outline-color: #f97316;
  outline-offset: 4px;
}
Browser Result

Use the Tab key to focus the button. A four-pixel orange outline appears outside the blue border.

Common Mistakes

Setting Width Without a Visible Style

.box {
  outline-width: 5px;
}

The declaration is valid, but no outline normally appears because the initial outline style is none.

Using Negative Widths

.box {
  outline-width: -3px;
}

Negative outline widths are invalid.

Using Percentage Values

.box {
  outline-width: 10%;
}

The property does not accept percentages.

Using auto

.box {
  outline-width: auto;
}

The auto keyword is not valid for outline-width. It is supported by outline-style.

Confusing Width with Offset

outline-width controls thickness, while outline-offset controls spacing.

Expecting Layout Changes

Changing outline thickness does not affect the element's box dimensions.

Using Zero Width for Focus Indicators

A zero-width outline is not visible and should not be used to remove focus indicators without an accessible replacement.

Expecting Fixed Keyword Thicknesses

The exact thicknesses of thin, medium, and thick are browser-defined.

Forgetting Shorthand Resets

A later outline shorthand declaration resets omitted outline longhand values, including outline-width.

Important Considerations

Keep the following points in mind when using outline-width:

  • The property controls the thickness of an element's outline.
  • Its initial value is medium.
  • The property is not inherited.
  • It applies to all elements.
  • It accepts thin, medium, and thick.
  • The exact thickness of keyword values is browser-defined.
  • It accepts non-negative CSS length values.
  • Negative widths are invalid.
  • Percentage values are not supported.
  • auto is not a valid outline width.
  • Zero width prevents the outline from being visible.
  • A visible outline requires an appropriate outline style.
  • outline-style: none and outline-style: hidden prevent visible outlines.
  • Outline width does not affect layout dimensions.
  • Outlines may overlap nearby content.
  • Outline thickness cannot be controlled independently for each side.
  • outline-color controls the outline color.
  • outline-style controls the line style.
  • The outline shorthand combines width, style, and color.
  • A shorthand declaration resets omitted outline longhand values.
  • outline-offset controls spacing independently of width.
  • Outlines are commonly used as keyboard focus indicators.
  • :focus-visible can be used to apply focus styling.
  • Focus indicators should remain clearly visible.
  • Thick outlines may be clipped by ancestor containers.
  • Outline width can be animated between compatible computed lengths.

Browser Support

The CSS outline-width property is Baseline - Widely available and has been supported in major browsers for many years.

Modern versions of Chrome, Edge, Firefox, Safari, and other major browsers support keyword and length values for outline thickness.

The exact thickness of thin, medium, and thick may vary between browsers.

For current compatibility information, visit Can I Use? and search for outline-width.

Specifications

The outline-width property is defined in CSS Basic User Interface Module Level 4.

CSS Basic User Interface Module Level 4: outline-width

The specification defines the available width values and how outline thickness is calculated.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: outline-width