Lesson 6 of 50
cssBox‑Sizing Property
5 mins
Course progress12%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 6 of 50
css5 mins
Keep these ideas in mind as you work through the lesson.
The box-sizing property tells the browser how to calculate an element’s total width and height.
| Value | Calculation |
|---|---|
content-box (default) | width = content only; padding & border are added outside. |
border-box | width = content + padding + border; the declared size is the final visible size. |
Why border-box is popular
/* Global reset */
*, *::before, *::after { box-sizing:border-box; }
.card {
width: 100%; /* Fill the column */
padding: 1.5rem; /* Safe inner space */
border: 2px solid #e0e0e0;
background: #fff;
/* No need to subtract padding from width – border-box handles it */
}
When you later change
paddingto2rem, the card’s outer width stays 100 % of its container.