Box Model

christian.dinh's avatar
Published Jul 27, 2021Updated Sep 9, 2021
Contribute to Docs

The Box Model is a CSS layout mechanism that the web browser uses to render content organized by box-shaped elements. Each element is made of four specific areas:

  • width and height: The width and height of the content area.
  • padding: The amount of space between the content area and the border.
  • border: The thickness and style of the border surrounding the content area and padding.
  • margin: The amount of space between the border and the outside edge of the element.

CSS Box Model Diagram

Content Area

This area contains the actual content of an element, including text and images. It also sometimes has a background-color or background-image.

Padding Area

This area is located between the content and border areas. It can be changed on the top, right, bottom and left sides.

Border Area

This area is located between the margin and padding areas. Their thickness and style can be changed.

Margin Area

This is the outermost area in the Box Model. It borders with the margin areas of neighboring elements. It can be changed on the top, right, bottom and left sides.

All contributors

Contribute to Docs

Learn CSS on Codecademy