agyanadda@gmail.com

CSS Box Sizing

CSS Box Model 1 min read Updated Dec 1, 2026 Topic 17 of 39

box-sizing decides what width and height include.

  • content-box (default): width = content only. Padding and border are added.
  • border-box: width = content + padding + border. The box stays the size you set.

Common reset

Most projects start with:

*, *::before, *::after { box-sizing: border-box; }

This makes layouts much easier — a width: 50% column stays 50% even with padding.

Example

Example — content-box vs border-box HTML
<style>
  div { width: 250px; padding: 20px; border: 5px solid #333; margin-bottom: 10px; }
  .content { box-sizing: content-box; background: #ffe2d6; }
  .border { box-sizing: border-box; background: #d6f5e3; }
</style>

<div class="content">content-box: 300px wide</div>
<div class="border">border-box: 250px wide</div>

Test Yourself With Exercises

Exercise 1 Multiple Choice

With border-box, width includes:

Exercise 2 True / False

content-box is the default value.

Exercise 3 Fill in the Blank

box-sizing: ___-box; keeps the size you set.

Frequently Asked Questions

No. Margin is always outside the box and never part of width.