CSS paddingProperty


Example

Set the padding of a P element:

p { padding:2cm 4cm 3cm 4cm; }

Try it Yourself »

Property definition and usage instructions

The padding shorthand property sets all padding properties in one declaration. This property can have 1 to 4 values.

Example:

  • padding:10px 5px 15px 20px;
    • Top padding is 10px
    • Right padding is 5px
    • Bottom padding is 15px
    • Left padding is 20px

  • padding:10px 5px 15px;
    • Top padding is 10px
    • Right and left padding are 5px
    • Bottom padding is 15px

  • padding:10px 5px;
    • Top and bottom padding are 10px
    • Right and left padding are 5px

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

Note:Negative values are not allowed.

Default value: 0
Inherited: no
version: CSS1
JavaScript Syntax: object.style.padding="10px 5px"


Browser Support

The numbers in the table indicate the first browser version that supports the property.

Property
padding 1.0 4.0 1.0 1.0 3.5

Property value

Value Description
length Specifies the padding value in specific units, such as pixels, centimeters, etc. The default value is 0px.
% Specifies the padding as a percentage based on the width of the parent element.
inherit Specifies that padding should be inherited from the parent element.


Related Articles

CSS Tutorial:CSS Padding

other extensions