The CSS box model
All web pages consist of elements rendered one after another. The CSS box model is one of the models that determine how much space an element can take on a web page, allowing us to customize the default layout scheme.
According to this model, each HTML element is placed in a "box." The CSS syntax for defining the box model is straightforward, as it involves setting values for the padding, border, and margin properties of an element.
The box itself is akin to a Russian doll — it's actually 4 boxes placed inside the other, starting from the innermost:
- Content: the text, image, or other media content inside the element
- Padding: the space between the box's content and its border
- Border: the line between the box's padding and margin
- Margin: the space between the box and surrounding boxes
Together, this is everything a browser needs to render an element's box.