Skip to content
FLAVIO COPES
flaviocopes.com
2026

The CSS Box Model

By Flavio Copes

Learn how the CSS box model works: every element is a box made of a content area, padding, border and margin, and by default width applies to the content area.

~~~

Every CSS element is essentially a box. Every element is a generic box.

The box model explains the sizing of the elements based on a few CSS properties.

From the inside to the outside, we have:

The best way to visualize the box model is to open the browser DevTools and check how it is displayed:

Firefox DevTools Layout panel showing CSS box model visualization with content area, padding, border, and margin layers

Here you can see how Firefox tells me the properties of a span element I highlighted. I right-clicked on it, pressed Inspect Element, and went to the Layout panel of the DevTools.

See, the light blue space is the content area. Surrounding it there is the padding, then the border and finally the margin.

By default, if you set a width (or height) on the element, that is going to be applied to the content area. All the padding, border, and margin calculations are done outside of the value, so you have to take this in mind when you do your calculation.

You can change this behavior using Box Sizing.

Tagged: CSS · All topics
~~~

Related posts about css: