content-box
width applies only to the content area. Padding and border increase final size.
box-sizing controls what width and height actually mean. With border-box, the browser includes padding and border inside the declared size.
*, *::before, *::after {
box-sizing: border-box;
}
Box Model
By default, CSS uses content-box. That means width controls the content area only. Padding and border are added on top, so the final rendered box can become wider than the width you wrote.
With border-box, width includes content, padding and border. This usually matches how designers and developers think about component size.
Most modern projects set border-box globally because it makes cards, columns, inputs and responsive layouts much easier to reason about.
width applies only to the content area. Padding and border increase final size.
width includes content, padding and border. This is usually easier to control.
Apply border-box to all elements and pseudo-elements for predictable sizing.
Computed sizes can include min-width, max-width, flex rules and content limits.
Visual model
Layout debugging becomes much easier when you can point to the exact part of the box that creates the visual result: inner space, outer space, edge, size or overflow behavior.
300px content + 48px padding + 4px border = wider than expected.
300px total width contains content, padding and border together.
Examples
*,
*::before,
*::after {
box-sizing: border-box;
}
.panel {
width: 320px;
padding: 24px;
}
.panel {
width: 320px;
padding: 40px;
border: 4px solid currentColor;
/* final width is no longer 320px */
}
Rules that matter
Box model CSS should make the interface easier to reason about. When a value cannot be explained, it usually becomes a future layout bug.
It matches the mental model most people expect when they set width.
Decorative before and after boxes should follow the same sizing logic.
Images and inputs can have their own intrinsic sizing behavior.
If the box is too wide, solve sizing before clipping content.
border-box and max-width make responsive components easier.
Everyone should know whether the project uses content-box or border-box.
Production thinking
box-sizing prevents the classic CSS surprise where an element becomes wider because padding was added after width was already defined.
Predictable sizing helps keep form fields, buttons and focus states from clipping or overflowing.
A border-box reset belongs near the start of your stylesheet, before component rules depend on sizing assumptions.
Stable boxes reduce visual jumps and improve the reading experience, especially on mobile.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If the answer is vague, change the lab CSS and inspect the box again.
Senior audit upgrade
Most modern projects use border-box globally because widths become easier to predict. Third-party widgets can still assume content-box, so isolate carefully.
* { box-sizing: border-box; } is common because padding and borders stay inside declared width.
Embedded widgets may bring their own sizing assumptions. Test forms, iframes and vendor components.
Everyone on the project should know which sizing model is expected.