CSS padding Property


The CSS padding property is used for creating space around the content of an element. CSS provides different properties, with the help of which you can set the padding for an element’s each side (right, left, top and bottom).

With the help of the following properties you can set the padding for each side of an element:

  • padding-top
  • padding-bottom
  • padding-left
  • padding-right

As you can guess, for the top, we use padding-top, for bottom padding-bottom, for left side padding-left and right padding-right.

All the padding properties can have the values below:

  • length, which is used for specifying a padding in px, pt, cm, etc,
  • %, which specifies a padding in % of the width of the containing element,
  • inherit , which specifies that the padding must be inherited from its parent element.

Take into account, that CSS padding property cannot accept negative values. Its default value for all padding properties is 0.

Note: Padding creates extra space within an element, while margin creates extra space around an element.

If the padding property has four values:

  • padding:10px 5px 15px 20px;
    • top padding is 10px
    • right padding is 5px
    • bottom padding is 15px
    • left padding is 20px

If the padding property has three values:

  • padding:10px 5px 15px;
    • top padding is 10px
    • right and left padding are 5px
    • bottom padding is 15px

If the padding property has two values:

  • padding:10px 5px;
    • top and bottom padding are 10px
    • right and left padding are 5px

If the padding property has one value:

  • padding:10px;
    • all four paddings are 10px

CSS Syntax

padding: length|initial|inherit;

Supported Browsers: The browser supported by property are listed below:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • IE Phone
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example -