Padding vs. margin in CSS

svg viewer
svg viewer
  1. Padding is the distance of the element from the elements inside it.
  1. Margin is the distance of the element from the adjacent elements.

Both of these properties are used to set up gaps on a page, but their methods are different.

  1. Padding creates the gap by either increasing its own size or ​decreasing the size of the contents inside it.
  1. Margin creates the gap by pushing adjacent elements away from it.
  1. Padding​ is used when the contents inside the container should not be touching the border of the container.
  1. Margin is used when the two elements should be separated enough that they don’t touch each other.
svg viewer
svg viewer
  1. Padding is used to increase the size of an element.
  1. Margin is used to bring an element to the center.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved