CSS Shorthand for Margin and Padding

The margin and padding CSS properties allow you to specify between one and
four values. This is something I use often but find difficult to remember how it works.

With four values remember to start at the top and go clockwise around the box like so: top,right,bottom,left

padding:10px 20px 30px 40px;

top padding is 10px
right padding is 20px
bottom padding is 35px
left padding is 40px

Using three values: 1st is top, 2nd is left/right, 3rd is bottom

padding:10px 20px 30px;

top padding is 10px
right and left paddings are 20px
bottom padding is 30px

Using two values 1st is top and bottom, 2nd is left/right

 padding:10px 20px;

top and bottom paddings are 10px
right and left paddings are 20px

Using one value is applied to all four sides

 padding:20px;

all four paddings are 20px

Leave a Reply