AI Workshop: learn to build apps with AI →
CSS Box Model
Understand the CSS box model, box-sizing, margins, padding, and borders

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


Every element in CSS is essentially a box. Understanding the box model is fundamental to mastering CSS layout.

The box model describes how elements are sized and spaced, consisting of four layers from inside to outside:

  1. Content - The actual content (text, images)
  2. Padding - Space between content and border
  3. Border - The edge around the padding
  4. Margin - Space outside the border

In this unit, you’ll learn how to control each layer to create precise layouts.

Lessons in this unit:

0: ▶︎ Introduction
1: Understanding the CSS Box Model
2: How to Use CSS Box Sizing
3: How to Use CSS Margin
4: How to Use CSS Padding
5: How to Style CSS Borders