The CSS Box Model

All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout. The CSS box model is essentially a box that wraps around HTML elements, and it consists of: margins, borders, padding, and the actual content. The box model allows us to add a border around elements, and to define space between elements. Here is an illustration and explanation of the box model:

CSS box-model

Explanation of the different parts:

  • Margin - Clears an area outside the border. The margin is transparent

  • Border - A border that goes around the padding and content

  • Padding - Clears an area around the content. The padding is transparent

  • Content - The content of the box, where text and images appear
Back button Table of Contents Next button