Web - Spacing Between Elements
Code Life
By Pierre Marsaa
Introduction to Spacing in CSS
The Box Model is a crucial concept in CSS that describes the rectangular boxes generated for elements in the document tree and how their dimensions are calculated.
Box Model - source
We already talked about margin and padding
If you remember correctly, we already talked about margin and padding in introduction to css. This is a gentle reminder + we apply them to box model.
To control the space between elements, CSS provides two main properties: margin and padding.
These properties are part of the CSS Box Model, which defines how elements are rendered on the page:
↗️
Loading editor...
↶
↷
In this example, you can see:
- margin creates space outside the element (the green area around the blue box)
- padding creates space inside the element (between the content and the border)
Verify