CSS CSS Basics The Box Model Margins

Padding instead of Margin

Can't we use padding for creating some space instead of margin in h2 and h3.

1 Answer

Nejc Vukovic
Nejc Vukovic
Full Stack JavaScript Techdegree Student 36,268 Points

Sure you can.

But imagine that the h2 and h3 have borders around them. Lets say 5px would be more than enough.

And now imagine you want to give them a little more space between them.

If you add padding to the elements the borders will still stick together. But by giving them a margin property you separate them from each other.

With padding you expand/decrease the space between the h2 or h3 element to the border. With margin you expand/decrease the space between the h2 or h3 element to the next element in the document flow.

LINK here the bo model is explained and presented.

Hope this helps.