box-sizing
The CSS property that decides whether width and height measure only the content (content-box) or include padding and border (border-box).
In more detail
With content-box, a 200px box with 16px padding and a 2px border is 236px wide on screen. With border-box it stays 200px and the content shrinks, which is far easier to reason about, so most CSS resets apply border-box to everything.
Example
*, *::before, *::after { box-sizing: border-box; }Related terms
- CSS box model — The rule that every element is drawn as a rectangle made of four layers: content, then padding, then border, then margin.
- CSS reset — A small stylesheet loaded first that removes browser default styles and sets sensible base rules such as border-box sizing.
- padding — The space inside an element between its content and its border, filled with the element's background.
- border — The line drawn around an element's padding, with its own width, style and colour.
Taught in
- Modern Box Model, Box Sizing, Display Types And Flow Layout — Frontend Architecture & Web Platform