🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Box Sizing

Control how the browser calculates element dimensions. Learn why border-box is essential for modern layouts.

style.css
* {
box-sizing: border-box;
}
.box {
width: 200px;
padding: 20px;
}
📦
box-model.html
1 / 10
📦

Tutor:Welcome. In CSS, every element is a box. But how that box's size is calculated is crucial for your layout.


CSS Layout Mastery

Unlock nodes by learning the Box Model logic.

Concept 1: Everything is a Box

In CSS, every element is a rectangular box. The box-sizing property controls how the size of that box is calculated.

System Check

What is the default box-sizing value in CSS?


Community Layouts

Share Resets

Do you use a custom box-sizing reset? Share your snippet.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Box Sizing

Author

Pascual Vila

Frontend Instructor.

The box-sizing property allows you to define how the width and height of an element are calculated: should they include padding and borders, or not?

Content-Box (Default)

By default, CSS sets box-sizing: content-box. In this mode, if you set an element's width to 100 pixels, then the element's content box will be 100 pixels wide, and the width of any padding or border will be added to that final width, making the element wider than 100px.

Border-Box (The Fix)

box-sizing: border-box tells the browser to account for any border and padding in the values you specify for an element's width and height. If you set an element's width to 100 pixels, that 100 pixels will include any border and padding you added, and the content box will shrink to absorb that extra width.

Best Practices

Most modern web developers find border-box easier to reason about. It is common to apply this setting to all elements using the universal selector:

* {
  box-sizing: border-box;
}

Box Model Glossary

box-sizing
A CSS property that defines how the user agent should calculate the total width and height of an element.
content-box
The default value. Width and height apply only to the content of the element. Padding and border are added outside of these dimensions.
border-box
Width and height apply to all parts of the element: content, padding, and borders. The content area shrinks to accommodate them.
Universal Reset
A technique using the * selector to apply box-sizing: border-box to all elements on a page to ensure consistent sizing behavior.