Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS padding property

CSS padding property

Example

Set the padding of a p element:

p

{

padding:

2

cm

4

cm

3

cm

4

cm

;

}

Try it »


Property definition and usage

The padding shorthand property sets all padding properties in a single declaration. This property can have from one to four values.

Example:

- The top padding is 10px - The right padding is 5px - The bottom padding is 15px - The left padding is 20px - The top padding is 10px - The right and left padding are 5px - The bottom padding is 15px - The top and bottom padding are 10px - The right and left padding are 5px - All four padding values 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 this property.

property
padding 1.0 4.0 1.0 1.0 3.5

Attribute values

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

Related Articles

CSS Tutorial: CSS Padding