What is the difference between padding and margins?

tmirror
What is the difference between padding and margins?
For those who would like to know more about HTML and CSS, in this post we will learn the differences between margin and padding CSS properties that are used to add space between the HTML elements, thus preventing the elements from getting 'stuck' together. Although both have similar functions, each work in a different way. Padding determines the inner margins, being used for changing the distance between the content of a given element and its border. Margin is the space outside of an element affecting how far the element is away from other elements. For a better understanding of how the padding and margin work, take a look at the picture below: Just as you have the option to define the borders for each side of your HTML elements (eg. borders for the sidebar), you can do the same with the margin and padding properties . All you need to to do is to change the top, right, bottom and left values​​. The values that you can use include: pixels ( px ), centimeters ( cm ), millimeters ( mm ).…