π Introduction
The outline-width property in CSS controls the thickness of an elementβs outline. Outlines are similar to borders, but they do not affect layout, can overlap other elements, and are commonly used for accessibility highlights (like focus states). Understanding outline-width helps you create accessible and visually clear UI components. β¨
π― Why Use outline-width?
- To highlight focused or active elements π
- To create non-invasive visual emphasis (doesnβt shift layout) π¨
- To improve accessibility for keyboard users β¨οΈ
- To debug layout issues (temporary outlines) π§ͺ
β¨ Syntax
Syntax
selector {
outline-width: <length> | thin | medium | thick;
}Note
outline-style to be visible, just like borders needborder-style.π§© Accepted Values
1. thin
A small, subtle outline (browser-defined, usually ~1px).
2. medium (default)
Standard outline thickness (~2β3px).
3. thick
Bold outline for strong emphasis (~4β5px).
4. Length Value
Length Example
.box {
outline-width: 6px;
}π Difference Between Outline and Border
| Feature | Border | Outline |
|---|---|---|
| Affects Layout? | Yes β adds to element size | No β drawn outside the box |
| Can Overlap? | No | Yes |
| Corner Radius? | Supports border-radius | Ignores border-radius unless outline-offset is used |
| Purpose | Design / structure | Highlight / accessibility |
π₯ Practical Examples
1. Focus Outline (Accessibility)
Focus Example
button:focus {
outline-width: 3px;
outline-style: solid;
outline-color: #007bff;
}2. Thick Outline for Emphasis
Thick Outline
.alert {
outline: thick solid red;
}3. Using Custom Thickness
Custom Width
.highlight {
outline-style: dashed;
outline-width: 5px;
outline-color: orange;
}4. Debug Boxes
Developers often use outlines because they don't affect layout.
Debug Example
* {
outline: 1px solid rgba(255, 0, 0, 0.4);
}π Just the Keywords
| Keyword | Approx Width |
|---|---|
| thin | ~1px |
| medium | ~2β3px |
| thick | ~4β5px |
πΌοΈ Visual Demo
Further details can be found at: https://dummyimage.com/900x250/eeeeee/000000&text=outline-width+demo
π Conclusion
The outline-width property is a simple yet important tool for defining the thickness of an elementβs outline. Outlines maintain accessibility, highlight interactions, and assist in layout debugging β without affecting box size. Combine outline-width with outline-style and outline-colorfor complete outline customization. π