When should I use an outline instead of a border in CSS?
Quick answer
Use an outline for a visible mark outside an element’s border that should not take up layout space or shift surrounding content. It can be useful for indicating keyboard focus, and outline-offset adjusts its distance from the border. Use a border for the element’s regular visual edge. If you remove the browser’s default focus style, provide another visible focus indicator. [S1]
The question, the details, the next step.
A practical checklist
Decide whether the edge is part of the element’s regular appearance.
Use an outline for a separate outside mark that should not take layout space.
Keep a visible focus indicator on interactive elements.
Replace a removed default focus style with another visible indicator.
Adjust outline spacing with
outline-offsetwhen needed.
A few more useful answers
Does an outline shift content around the element?
No. An outline takes up no layout space, so it does not shift surrounding content. [S1]
How can I move an outline farther from the border?
Use outline-offset to adjust the outline’s distance from the border. [S1]
Is it okay to set `outline: none`?
Only if you provide another visible focus indicator for interactive elements; removing the default outline removes the browser’s default focus style. [S1]
Sources
References used for this guide.
- [S1] MDN: outline CSS property developer.mozilla.org · Checked
