C

CSS Box Model

Visualize content, padding, border, and margin layers with an interactive box model explorer.

Web Development v1.0.0 23 uses
Step 1 of 6

Step 1: What is the Box Model?

Every HTML element is rendered as a rectangular box. The CSS box model describes the layers that make up each box, from the inside out:

  • Content — the actual text, image, or child elements
  • Padding — transparent space between content and border
  • Border — a visible edge around the padding
  • Margin — transparent space outside the border, separating the element from neighbors

Here is the classic box model diagram:

margin
border
padding
Content

Key terms:

  • Total width = margin-left + border-left + padding-left + content width + padding-right + border-right + margin-right
  • Total height follows the same pattern vertically
  • The box-sizing property changes how width and height are calculated

About This Lab

Every HTML element is a box. In this lab, you'll explore the four layers of the CSS box model — content, padding, border, and margin — adjust each interactively, understand box-sizing, see how dimensions are calculated, and master the relationship between these properties.

How It Works

  1. 1 Read each step's explanation of the box model
  2. 2 Adjust sliders to change padding, border, and margin
  3. 3 Watch the box model diagram update in real time
  4. 4 Compare content-box vs border-box sizing
  5. 5 Complete the quiz to test your understanding

Translate

ESC