What is the CSS outline property and how does it differ from border?
Answer
Both outline and border draw a line around an element, but with important differences. Border is part of the box model — it takes up space and affects the element's layout. Outline is drawn outside the border and does not take up space — it does not affect the element's dimensions or surrounding layout. Outlines cannot have different widths per side (no outline-top) and cannot have rounded corners (though outline-offset can space it away). The most important use of outline is for keyboard focus indicators: browsers add an outline to focused elements by default for accessibility. Never use outline: none without providing an alternative focus style, as it harms keyboard navigation accessibility.
Previous
What are srcset and sizes attributes for responsive images?
Next
What is the critical rendering path in browsers?
More HTML / CSS Questions
View all →- Intermediate How does the CSS cascade work?
- Intermediate What is BEM (Block Element Modifier) methodology in CSS?
- Intermediate What are CSS custom properties (CSS variables)?
- Intermediate What is the difference between em, rem, px, vh, and vw units in CSS?
- Intermediate How does Flexbox differ from CSS Grid? When would you use each?