<?xml version="1.0" encoding="utf-8"?>

Applying CSS margin property

Applying CSS margin property

Margins and padding can accomplish the same thing in a lot of situations, making it difficult to determine which one is the best choice. In CSS, there's often more than one way to solve your problem.

Here are the key differences to keep in mind:

  • Padding is included in the click area of an element, while margins aren't
  • The padding of a box has a background, while margins are always transparent
  • Margins collapse vertically,[1] while padding doesn't
Improve your UX & Product skills with interactive courses that actually work