CSS margin property

Usage

A shorthand way of setting the margin for all four sides of an element. Can contain up to four different values depending on how many different margins you want to specify.

Variations

  • margin-top
  • margin-right
  • margin-bottom
  • margin-left

Values

  • margin-top, margin-right, margin-bottom, and margin-left values

Example

Code:

/* All margins 10px */
p { margin: 10px }

/* Top and bottom 10px, left and right 1em */
p { margin: 10px 1em }

/* Top 10px, left and right 1em, bottom 5% */
p { margin: 10px 1em 5% }

/* Top 10px, right 1em, bottom 5%, left auto */
p { margin: 10px 1em 5% auto }