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

CSS margin shorthand property

CSS margin shorthand property Bad Practice
CSS margin shorthand property Best Practice

Margin shorthand property allows you to specify all necessary values at once separated by gaps. What happens if you don't define all 4 of them?

  • When you set only one value, it applies to all four sides
  • When you set two values, the first one defines the top and bottom margin, while the second defines the left and right margin
  • When you set 3 values, the first one defines the top margin, the second defines the left and right, and the third defines the bottom

Top contributors

André Luis Merlone Perissinotto

Topics

Share

Improve your UX & Product skills with interactive courses that actually work