CSS Box Model

What is the CSS Box Model?

The CSS Box Model is a box that wraps around every HTML element. It consists of the following parts:

CSS Box Model Example

This box demonstrates the CSS Box Model. Modify the code in the CSS to see the changes!

The box above has the following properties:

By default, the width and height only include the content area. When padding, border, and margin are applied, the total size of the box will be larger than the specified width and height unless you use the box-sizing: border-box; property.

Understanding box-sizing

In CSS, the default value of box-sizing is content-box, meaning the width and height of an element only apply to the content area. If you want the width and height to include the padding and border, you need to use box-sizing: border-box;.

Quiz: Test Your Knowledge

1. Which part of the CSS Box Model is outside of the border?




2. What is the default value of box-sizing?



3. If you set box-sizing: border-box;, what happens to the width and height of an element?