CSS box model
The rule that every element is drawn as a rectangle made of four layers: content, then padding, then border, then margin.
In more detail
Width and height apply to the content box by default, so padding and border add to the element's visible size. Margins sit outside the border and separate the element from its neighbours.
Related terms
- 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.
- margin — Transparent space outside an element's border that pushes neighbouring elements away.
- box-sizing — The CSS property that decides whether width and height measure only the content (content-box) or include padding and border (border-box).
Taught in
- Modern Box Model, Box Sizing, Display Types And Flow Layout — Frontend Architecture & Web Platform