Margin - Shorthand Property

To shorten the code, it is possible to specify all the margin properties in one property, using what is called a shorthand property. The shorthand property for all the margin properties is "margin". The margin property can have from one to four values:

4 Values: margin: 25px 50px 75px 100px;
  • top margin is 25px
  • right margin is 50px
  • bottom margin is 75px
  • left margin is 100px
3 Values: margin:25px 50px 75px;
  • top margin is 25px
  • right and left margins are 50px
  • bottom margin is 75px
2 Values: margin: 25px 50px;
  • top and bottom margins are 25px
  • right and left margins are 50px
1 Value: margin: 25px;
  • all four margins are 25px

The white areas are the elements, while the blue areas are the margins. It's blue because I made the table cells background color blue and margins are transparent.

Back button Table of Contents Next button