C
CSS Box Model
Visualize content, padding, border, and margin layers with an interactive box model explorer.
Web Development
v1.0.0
154 uses
C
CSS Box Model
Esc
or
Ctrl+Shift+F
to exit
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-sizingproperty changes howwidthandheightare 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 Read each step's explanation of the box model
- 2 Adjust sliders to change padding, border, and margin
- 3 Watch the box model diagram update in real time
- 4 Compare content-box vs border-box sizing
- 5 Complete the quiz to test your understanding
More Labs in Web Development
J
JSON & APIs
Web DevelopmentLearn JSON syntax, parse and build data structures, and explore how REST APIs work interactively.
I
Intro to HTML
Web DevelopmentLearn the building blocks of the web — write your first HTML elements and see them render in real time.
C
CSS Flexbox Playground
Web DevelopmentMaster CSS Flexbox by experimenting with flex properties and seeing instant visual results.