Skip to main content

What is the difference between "padding" and "margin" in CSS?

  • The "padding" and "margin" properties are used to control the space around the elements in an HTML document.

"padding" is the space inside an element, between the element's content and its border. "padding" can be applied to all four sides of an element, or to specific sides, using the "padding-top", "padding-right", "padding-bottom", and "padding-left" properties.

"margin" is the space outside an element, between the element's border and the next element. "margin" can be applied to all four sides of an element, or to specific sides, using the "margin-top", "margin-right", "margin-bottom", and "margin-left" properties.

The main difference between "padding" and "margin" is the location of the space. "Padding" is inside the element, while "margin" is outside the element.