🖌️ CSS outline-width
: Adjusting the Thickness of Element Outlines
The CSS outline-width
property lets you control how thick or thin the outline around an element appears. Outlines are often used to highlight elements—especially on focus or hover—without impacting the layout, and the outline-width
property helps you fine-tune their visual weight.
🧾 What is outline-width
?
outline-width
defines the thickness of an outline line drawn outside an element’s border. It accepts specific length values or predefined keywords that correspond to different thickness levels.
🧬 Syntax
selector {
outline-width: <length> | thin | medium | thick | inherit | initial | unset;
}
Values explained:
Value | Description |
---|---|
<length> | Specific width using units like px , em , rem (e.g., 3px , 0.1em ) |
thin | Thin line (typically around 1px) |
medium | Default thickness (browser dependent, usually 3px) |
thick | Thick line (usually around 5px) |
inherit | Inherits the value from the parent element |
initial | Resets to the default (medium ) |
unset | Resets to inherited or initial value |
🎯 Example Usage
1. Thin outline for subtle highlight
input:focus {
outline-width: thin;
outline-style: solid;
outline-color: blue;
}
Creates a delicate, thin blue outline when an input is focused.
2. Thick outline for strong emphasis
button:hover {
outline-width: 6px;
outline-style: dashed;
outline-color: red;
}
A thick, dashed red outline highlights buttons on hover.
3. Medium outline using keyword
div {
outline-width: medium;
outline-style: dotted;
outline-color: green;
}
Applies a default medium-width dotted green outline around a div.
🧠 Using outline-width
with Shorthand
You can combine width, style, and color in one line using the outline
shorthand:
lement {
outline: thick solid orange;
}
This sets a thick, solid orange outline in a concise way.
⚠️ Important Notes
- If
outline-style
is set tonone
(default), the outline won’t show even ifoutline-width
is set. - Choose outline widths that maintain good visibility without overwhelming the content.
- Use consistent outline widths in your UI for uniformity and accessibility.
✅ Browser Support
The outline-width
property is supported in all major browsers:
- ✅ Chrome
- ✅ Firefox
- ✅ Safari
- ✅ Edge
- ✅ Internet Explorer 8+
🔚 Conclusion
The outline-width
property offers a simple, effective way to control the thickness of outlines, helping you create clear, accessible focus states or highlight effects that fit your design. Whether you want a subtle line or a bold frame, outline-width
makes it easy to adjust without impacting layout.