Padding - Shorthand property

To shorten the code, it is possible to specify all the padding properties in one shorthand property. The shorthand property for all the padding properties is called "padding". This example demonstrates a shorthand property for setting all of the padding properties in one declaration, can have from one to four values.

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

The blue area is a div element with background set to bue and includes both padding and content of that element. The white space is created because the content has different amount of lines as content.

Back button Table of Contents Next button