liveBook · Manning

CSS box model

As explained in Web Design Playground

A CSS layout model that represents each element as a rectangular box consisting of content, padding, border, and margin.

The CSS box model is a friendly way to picture every element as a rectangle with four layers: content, padding, border, and margin. These layers help organize a page by controlling its size, whitespace, and position. section 9.0 section 9.1

Imagine an element as a small package with these layers:

  • Content holds the text, image, or other material inside the box. section 9.1
  • Padding adds breathing room between the content and the border. section 9.1
  • Border surrounds the content and padding with an edge. section 9.1
  • Margin adds space outside the border, separating this box from others. section 9.1
09_01.png

Use the figure to visualize the four nested regions and see how the box surrounds an element. section 9.1

Padding and margin create visual organization through whitespace, while box-related properties help move elements into a preferred layout. The model applies to block elements such as div, h1, and p, as well as inline elements such as span, em, and a. section 9.1

A menu with room to breathe

A list can use padding to separate menu items. In the example, the first li receives extra left padding to balance the final item's right padding and keep the menu centered. When the box edges are difficult to see, the outline property can draw a line around the outside of the border. section 9.10

How Web Design Playground covers it

How deep it goes
Defines four box regions and their visual roles, then stops before broader page layout.
Examples
Uses a menu list, balanced li padding, and the outline property to make box edges visible.
What you can do after
Apply padding, borders, margins, and outlines to control spacing, appearance, and element placement.
How it connects
Connects content, padding, border, margin, whitespace, positioning, and layout.

Also explained in

Compare how 6 books explain CSS box model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground. The section links point to the parts of the book it draws on.