The box-sizing property sets how an element’s width and height are calculated: content only (content-box), or content plus padding and border (border-box).
The initial value is content-box. Margin is never included. Many layouts use border-box so a set width stays the final outer size when padding or border is added.
Standard-track.
Not deprecated and not experimental. Baseline widely available. Some form controls already use border-box by default in browsers.
Shared scaffold. Both use 160px, 20px padding, and an 8px border.
content-box grows. Outer width becomes 216px.
border-box stays put. Outer width stays 160px.
Same CSS numbers, different totals. That is the whole point of box-sizing.
Edge Cases & Pitfalls
Remember what is inside the width — and what never is.
margin
Margin is never included
box-sizing does not touch margin. Space outside the border always adds to layout separately.
overflow
width: 100% + padding
With content-box, padding can push a 100% child past its parent. border-box usually prevents that.
min
Content cannot go negative
With border-box, huge padding cannot erase the box. Content size floors at 0.
forms
Some controls start as border-box
Browsers often use border-box for certain buttons and inputs. Do not assume every element is content-box.
global
Common reset pattern
Many projects set *, *::before, *::after { box-sizing: border-box; } once so sizing stays predictable. Try it in tryit 4.
Compatibility
Browser Support
box-sizing is a browser style property. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
box-sizing
Chrome 10+, Firefox 29+, Safari 5.1+, Edge 12+, Opera 7+, Internet Explorer 8+. Unprefixed in modern browsers.
98%global support
Google Chrome10+
Full support
Mozilla Firefox29+
Full support
Apple Safari5.1+
Full support
Microsoft Edge12+
Full support
Opera7+
Full support
Samsung Internet1+
Full support
Internet Explorer8+
Full support
box-sizingUniversally supported in modern browsers
Bottom line: Safe for production. No prefix is required in current browsers for content-box and border-box.
Remember
Key Takeaways
Role: decide whether width/height include padding and border.
Default:content-box — extras grow the box.
border-box: width stays the outer size; content shrinks.
Margin: always outside; never part of box-sizing.
One line:box-sizing chooses whether padding and border sit inside or outside your width.
Frequently Asked Questions
It controls whether width and height apply only to the content area, or also include padding and border.
The initial value is content-box. Padding and border are added outside the width and height you set.
content-box: width is content only. border-box: width includes content, padding, and border. Margin is never included.
No. Margin always sits outside the box and is not part of the box-sizing calculation.
With border-box, a declared width stays the final outer size when you add padding or border, which makes layout math easier.
It is Baseline widely available: Chrome 10+, Firefox 29+, Safari 5.1+, Edge 12+, Opera 7+, Internet Explorer 8+. It is a browser style property, not a Node.js feature.