CSS outline-color Property
The CSS outline-color property specifies the color of an outline drawn around an element.
Outlines are commonly used to highlight focused buttons, links, form controls, and other interface elements. The outline-color property changes only the outline's color, while outline-style and outline-width control its appearance and thickness.
outline-color Syntax
The outline-color property accepts a CSS color value. The color can be specified using a named color, hexadecimal notation, a color function, or a keyword such as currentColor.
Basic Syntax
selector {
outline-color: blue;
}
Hexadecimal Color
.box {
outline-color: #2563eb;
}
RGB Color
.box {
outline-color: rgb(37 99 235);
}
HSL Color
.box {
outline-color: hsl(221 83% 53%);
}
Using currentColor
.box {
outline-color: currentColor;
}
Transparent Color
.box {
outline-color: rgb(37 99 235 / 50%);
}
CSS-Wide Keywords
.box {
outline-color: initial;
}
.box {
outline-color: inherit;
}
.box {
outline-color: unset;
}
.box {
outline-color: revert;
}
.box {
outline-color: revert-layer;
}
The initial value is auto. When used, the browser determines the outline color, commonly using the element's current text color or a platform-defined color.
Property Values
| Value | Description |
|---|---|
<color> |
Specifies an outline color using any supported CSS color value. |
auto |
Allows the browser to determine the outline color. |
currentColor |
Uses the element's computed color value. |
transparent |
Creates a fully transparent outline color. |
initial |
Resets the property to auto. |
inherit |
Uses the computed outline color of the parent element. |
unset |
Resets the property to auto 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 | auto |
| Inherited | No |
| Applies to | All elements |
| Computed value | Computed color or auto |
| Animation type | By computed value type |
| Affects layout | No |
| Related shorthand | outline |
Valid Color Values
.box {
outline-color: red;
}
.box {
outline-color: #2563eb;
}
.box {
outline-color: rgb(37 99 235);
}
.box {
outline-color: hsl(221 83% 53%);
}
.box {
outline-color: currentColor;
}
Invalid Values
.box {
outline-color: 3px;
}
.box {
outline-color: solid;
}
.box {
outline-color: 50%;
}
These declarations are invalid because they do not specify a recognized outline color.
How It Works
The outline-color property determines the color used when an outline is drawn around an element.
An outline is drawn outside the element's border edge and does not contribute to the element's box dimensions.
Setting the Outline Color
.box {
outline-style: solid;
outline-width: 3px;
outline-color: #2563eb;
}
The element receives a three-pixel solid blue outline.
Changing Only the Color
.box {
outline: 3px solid blue;
}
.box.highlighted {
outline-color: orange;
}
The highlighted element keeps the same outline width and style but changes its color to orange.
Outline Color Without a Style
.box {
outline-color: red;
}
This declaration alone does not normally produce a visible outline because the initial outline-style value is none.
Outline Color and Layout
Changing an outline's color does not affect the element's width, height, margin, padding, or position.
Important Consideration
For a visible outline, make sure the element has an appropriate outline style and a nonzero outline width.
Named Colors
CSS named colors provide a simple way to assign an outline color without writing a hexadecimal or functional color value.
Blue Outline
.box {
outline: 3px solid;
outline-color: blue;
}
Green Outline
.box {
outline: 3px solid;
outline-color: green;
}
Orange Outline
.box {
outline: 3px solid;
outline-color: orange;
}
Multiple Named Colors
.primary {
outline-color: royalblue;
}
.success {
outline-color: seagreen;
}
.warning {
outline-color: darkorange;
}
Each class uses a different named color. A visible outline style must also be present.
Important Consideration
Named colors are convenient for simple examples, while hexadecimal values and color functions provide more precise color control.
Hexadecimal Colors
Hexadecimal color values allow precise control over an outline's red, green, and blue components.
Six-Digit Hexadecimal Color
.box {
outline: 3px solid;
outline-color: #2563eb;
}
Three-Digit Hexadecimal Color
.box {
outline: 3px solid;
outline-color: #f80;
}
The shorthand value #f80 represents #ff8800.
Eight-Digit Hexadecimal Color
.box {
outline: 3px solid;
outline-color: #2563eb80;
}
The final two hexadecimal digits specify the alpha channel, making the outline approximately 50% opaque.
Different Outline Colors
.box-one {
outline-color: #2563eb;
}
.box-two {
outline-color: #16a34a;
}
.box-three {
outline-color: #c2410c;
}
Important Consideration
Hexadecimal values are useful when an interface uses a defined color palette and consistent colors are needed across components.
CSS Color Functions
The outline-color property supports CSS color functions, including rgb(), hsl(), and other supported color formats.
RGB Color
.box {
outline: 3px solid;
outline-color: rgb(37 99 235);
}
RGB with Transparency
.box {
outline: 3px solid;
outline-color: rgb(37 99 235 / 60%);
}
HSL Color
.box {
outline: 3px solid;
outline-color: hsl(221 83% 53%);
}
HSL with Transparency
.box {
outline: 3px solid;
outline-color: hsl(221 83% 53% / 60%);
}
Using color-mix()
.box {
outline: 3px solid;
outline-color: color-mix(in srgb, blue 70%, white);
}
The color-mix() function creates a color by mixing blue and white.
Using CSS Variables
:root {
--focus-outline-color: #2563eb;
}
button:focus-visible {
outline: 3px solid;
outline-color: var(--focus-outline-color);
}
A custom property makes it easier to maintain consistent outline colors across multiple elements.
Using currentColor
The currentColor keyword uses the element's computed text color as its outline color.
Matching Text and Outline Colors
.box {
color: #2563eb;
outline: 3px solid;
outline-color: currentColor;
}
Both the text and outline use the same blue color.
Changing Colors Together
.box {
color: #2563eb;
outline: 3px solid currentColor;
}
.box:hover {
color: #c2410c;
}
When the text color changes on hover, the outline color changes with it.
Using currentColor with Buttons
button {
color: #1e40af;
outline: 2px solid currentColor;
}
Inherited Text Colors
.container {
color: #16a34a;
}
.container .box {
outline: 3px solid currentColor;
}
If the box inherits the text color from its parent, its outline uses that inherited color.
Important Consideration
currentColor is useful for consistent styling, but the resulting outline still needs sufficient contrast against surrounding content.
Transparent Outlines
The outline-color property supports transparency through the transparent keyword and color values with alpha channels.
Fully Transparent Outline
.box {
outline: 3px solid;
outline-color: transparent;
}
The outline has a defined style and width but is not visually distinguishable.
Partially Transparent Outline
.box {
outline: 3px solid;
outline-color: rgb(37 99 235 / 50%);
}
Transparent Hexadecimal Color
.box {
outline: 3px solid;
outline-color: #2563eb80;
}
Changing Opacity on Hover
.box {
outline: 3px solid;
outline-color: rgb(37 99 235 / 40%);
}
.box:hover {
outline-color: rgb(37 99 235 / 100%);
}
The outline becomes fully opaque when the element is hovered.
Important Consideration
Transparent and low-opacity outlines may not provide enough contrast for focus indicators. Use clearly visible colors for keyboard focus styling.
Using the outline Shorthand
The outline shorthand combines outline-width, outline-style, and outline-color into one declaration.
Shorthand Declaration
.box {
outline: 3px solid #2563eb;
}
Equivalent Longhand Declarations
.box {
outline-width: 3px;
outline-style: solid;
outline-color: #2563eb;
}
Both examples create the same outline.
Overriding the Shorthand Color
.box {
outline: 3px solid #2563eb;
outline-color: #16a34a;
}
The final outline is green because the later longhand declaration overrides the color component of the shorthand.
Shorthand Reset Behavior
.box {
outline-color: red;
outline: 3px solid;
}
The shorthand resets outline-color to its initial value because no color was included in the shorthand.
Using outline-offset
.box {
outline: 3px solid #2563eb;
outline-offset: 4px;
}
The outline-offset property is separate from the shorthand and controls the spacing between the outline and the border edge.
Focus Indicators
Outline colors are especially important for keyboard focus indicators because they help users identify the currently focused element.
Basic Focus Color
button:focus {
outline: 3px solid;
outline-color: #2563eb;
}
Using :focus-visible
button:focus-visible {
outline: 3px solid;
outline-color: #f97316;
outline-offset: 3px;
}
The :focus-visible pseudo-class applies styling when the browser determines that a visible focus indicator is appropriate, commonly during keyboard navigation.
Focus Colors for Form Controls
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
outline: 3px solid;
outline-color: #2563eb;
outline-offset: 2px;
}
Different Focus Colors
.primary-button:focus-visible {
outline: 3px solid #f97316;
}
.secondary-button:focus-visible {
outline: 3px solid #2563eb;
}
Different colors can be used as long as the focus indicators remain clearly visible.
Important Consideration
Do not remove the browser's default focus outline unless a suitable visible replacement is provided.
Accessibility Considerations
Choosing an appropriate outline color helps make keyboard focus indicators visible and improves navigation for users who do not rely on a mouse.
Maintain Sufficient Contrast
The outline should be clearly distinguishable from adjacent colors, including the element's background and surrounding page.
Avoid Invisible Focus Outlines
button:focus-visible {
outline-color: transparent;
}
This may make the focus indicator invisible if no other visible focus styling is present.
Provide a Clear Focus Indicator
button:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 3px;
}
Forced Colors Mode
In forced-colors environments, browsers may replace author-defined colors with system colors to maintain readability.
@media (forced-colors: active) {
:focus-visible {
outline: 2px solid Highlight;
outline-offset: 2px;
}
}
Avoid Color-Only State Changes
For error, success, or warning states, use additional text or visual indicators rather than relying entirely on outline color to communicate meaning.
Important Consideration
Test interactive elements using the Tab and Shift+Tab keys to verify that focus indicators remain visible across different backgrounds.
outline-color Example
This example demonstrates how the outline-color property changes the color of otherwise identical outlines.
HTML Example
<div class="outline-color-demo">
<div class="outline-box blue-outline">Blue</div>
<div class="outline-box green-outline">Green</div>
<div class="outline-box orange-outline">Orange</div>
<div class="outline-box purple-outline">Purple</div>
</div>
CSS Example
.outline-color-demo {
display: flex;
flex-wrap: wrap;
gap: 20px;
padding: 20px;
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-width: 4px;
}
.blue-outline {
outline-color: #2563eb;
}
.green-outline {
outline-color: #16a34a;
}
.orange-outline {
outline-color: #c2410c;
}
.purple-outline {
outline-color: #7c3aed;
}
Each box uses the same outline style and width. Only the outline-color value changes.
Interactive Focus Color Example
This example changes a button's outline color when it receives visible keyboard focus.
<button class="outline-focus-button" type="button">Focus Me</button>
.outline-focus-button {
padding: 12px 20px;
border: 2px solid #2563eb;
background-color: #fff;
color: #1e40af;
cursor: pointer;
}
.outline-focus-button:focus-visible {
outline-style: solid;
outline-width: 3px;
outline-color: #f97316;
outline-offset: 4px;
}
Use the Tab key to focus the button. The orange outline appears outside the blue border without changing the button's layout dimensions.
Common Mistakes
Setting a Color Without an Outline Style
.box {
outline-color: red;
}
The declaration is valid, but no outline normally appears because the initial outline style is none.
Using Length Values
.box {
outline-color: 3px;
}
The declaration is invalid because a length is not a color.
Using Outline Styles as Colors
.box {
outline-color: dashed;
}
The value dashed belongs to outline-style, not outline-color.
Using Transparent Focus Colors
A transparent focus outline may be invisible. Use a clearly visible color or provide another accessible focus indicator.
Expecting the Color to Affect Layout
Changing an outline's color does not affect the element's box dimensions or layout position.
Confusing outline-color with border-color
outline-color changes the outline color, while border-color changes the element's border color.
Forgetting Shorthand Resets
A later outline shorthand declaration resets any omitted outline longhand values, including outline-color.
Using Low-Contrast Colors
An outline that blends into the surrounding background may be difficult to see.
Expecting currentColor to Be a Fixed Color
The currentColor keyword follows the element's computed text color, which may change through inheritance, states, or other CSS rules.
Important Considerations
Keep the following points in mind when using outline-color:
- The property specifies the color of an element's outline.
- Its initial value is
auto. - The property is not inherited.
- It applies to all elements.
- It accepts standard CSS color values.
- Named colors, hexadecimal values, and CSS color functions are supported.
- The
currentColorkeyword uses the element's computed text color. - Alpha channels allow partially transparent outline colors.
- The
transparentkeyword creates a fully transparent outline color. - A visible outline normally requires an outline style other than
noneorhidden. - The outline width must also be greater than zero for a visible result.
- Outline colors do not affect layout dimensions.
- Outlines are drawn outside the element's border edge.
- The
outlineshorthand can set width, style, and color together. - A shorthand declaration resets omitted outline longhand values.
outline-offsetcontrols spacing independently of outline color.- Outline colors are commonly used for focus indicators.
:focus-visibleis useful for keyboard focus styling.- Focus indicators should have sufficient contrast against surrounding content.
- Do not remove visible focus indicators without providing an accessible replacement.
- Forced-colors environments may override author-defined outline colors.
- CSS custom properties can help maintain consistent outline colors.
- Outline colors can be animated between compatible color values.
Browser Support
The CSS outline-color 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 standard outline color values.
Some details, including automatic outline colors and forced-colors rendering, may vary between browsers and operating systems.
For current compatibility information, visit Can I Use? and search for outline-color.
Specifications
The outline-color property is defined in CSS Basic User Interface Module Level 4.
CSS Basic User Interface Module Level 4: outline-color
The specification defines outline color values and their rendering behavior.
For additional documentation and examples, consult MDN Web Docs.
