CSS Studio

Interactive Learning

On this tool

With content-box, width is only the content. Padding and border are added outside it, so the element grows. border-box keeps width fixed and shrinks the content instead.

Box Model

Orange is margin, yellow is border, green is padding, and the center is content.

What people get wrong

With content-box, width is only the content. Padding and border are added outside it, so the element grows. border-box keeps width fixed and shrinks the content instead.

Does CSS width include padding?
Only with box-sizing: border-box. The default, content-box, means width is the content area. Padding and border sit outside that width.
What is the difference between margin and padding?
Padding is space inside the border, around the content. Margin is space outside the border, between this element and its neighbors. Margin does not take background color.

Dimensions

200px
30px
10px
30px

Box sizing

Width is only the content. Padding and border are added outside it.

CSS editor
Edits the preview
Loading...
The page around the element
Margin
Border
Padding
200px content