agyanadda@gmail.com

CSS Box Model

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

Every HTML element is a rectangular box with four layers, from inside to outside:

  1. Content — text, images
  2. Padding — space inside the border
  3. Border — the line around the padding
  4. Margin — space outside the border, between elements

Total width

By default: width + left/right padding + left/right border.

Example: width: 200px; padding: 20px; border: 5px → total 250px.

Margins add space around the box but are not part of its size. Use DevTools to see the box model of any element.

Example

Example — Box model in action HTML
<style>
  .box {
    width: 200px;
    padding: 20px;
    border: 5px solid #1f386b;
    margin: 30px;
    background: #dbe8ff;
  }
</style>

<div class="box">Width 200px + padding 40px + border 10px = 250px wide.</div>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which layer is between the content and the border?

Exercise 2 True / False

Margin is the space outside the border.

Exercise 3 Fill in the Blank

width: 100px; padding: 10px; border: 0 gives a total width of ___px.

Frequently Asked Questions

Right-click → Inspect, then open the Computed or Layout tab in DevTools. It shows content, padding, border and margin sizes.