Writing a CSS, there is a particular rule that should be used in deciding when to use margin and when to use padding.
There are two ways in CSS for creating the space around your elements i.e. margins and padding. They are functionally identical but they behave in slightly different ways.
To be clear about the difference between padding and margin is that margins auto-collapse, and padding doesn’t.
When using margin and padding, a lot of the decision comes down to personal preference for use.
So, margin is on the outside of block elements where as padding is on the inside.
Thus, use margin to separate block from the things outside it and use the padding to move contents away from edges of the block.
In an element, margin is used to create the distance between that element and other elements of the page where as padding is used for creating distance between content and the border of an element. So, the margin is not part of an element where as padding is part of it.
Read Also: Cellpadding and Cellspacing in CSS
The another difference is that the padding is included in the click region and background image or color, but not the margin.
The below diagram gives visual understanding of the difference.
In today’s fast-paced and highly competitive marketing environment, even the most creative campaign is only…
We are NYC moving firm. Are you planning a flat move? Maybe a distance or…
Mobile devices, unlike desktops and laptops, can not be handled by dozens or hundreds of…
Augmented Reality- An immersive experience for the learners! Learning and education aren’t the same as…
On special days like birthdays and weddings, we all like to celebrate our loved ones…
A web application is different from a regular mobile or desktop application as it runs…