There are actually two box models in CSS, the standard and the alternate. By default, browsers use the standard model.
Note that the box model applies wholly to block boxes. Inline boxes only use some of the model.
inline-size
and block-size
or width
and height
.padding
and related properties.border
and related properties.margin
and related properties.In the standard box model (content-box
), padding and border is added to the defined width/height dimensions to get the total size taken up by the box.
.box { width: 200px; height: 100px; padding: 20px; border: 10px solid black; }
200 (content)
+ 40 (padding)
+ 20 (border)
= 260px100 (content)
+ 40 (padding)
+ 20 (border)
= 160pxIn the alternate box model (border-box
) the total size is the defined width/height.
200 - 40 (padding) - 20 (border)
= 140px