English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS reference manual

CSS @rules (RULES)

CSS attributes in full

Usage and examples of the CSS padding property

The CSS padding property can set padding on all four sides of an element. It ispadding-top,padding-right,padding-bottomandpadding-leftAbbreviated property of the attribute.

The table below provides usage instructions and version history for this property, as well as the syntax for using this property in JavaScript scripts.

Default Value:0
Applies to:All elements, except<tbody>,<thead>,<tfoot>,<tr>,<colgroup>and<col>. It also applies to::first-letter.
Inheritance:No
Animatable:Yes.Please refer to Animation Attributes.
Version:CSS 1,2,3
JavaScript Syntax:object.style.padding="20px 15px"

Syntax of padding usage

The syntax of this attribute is as follows:

padding: [ length | percentage] 1 to 4 values | initial | inherit

The following example demonstrates how to use the padding attribute.

  p.one {
   padding: 20px;
  }
  p.two {
   padding: 35px 15px;
  }
Test and see‹/›

This shorthand notation can take one, two, three, or four space-separated values.

  • if seta valuethen this padding applies to all4a face.

  • If setTwo valuesIf the first value is applied to the top and bottom, and the second value is applied to the right and left.

  • Three values respectivelyApplied to the top, horizontal (i.e., left and right), and bottom.

  • Four valuesApplied sequentially to the top, right, bottom, and left.

Attribute Value

The following table describes the value of this attribute.

ValueDescription
padding-topSet the padding to the top side of the element.
padding-rightSet the padding to the right side of the element.
padding-bottomSet the padding to the bottom side of the element.
padding-leftSet the padding to the left side of the element.
initialSet this attribute to its default value.
inheritIf specified, the associated element adopts the padding attribute value of its parent element.

Browser Compatibility

Browser Compatibility of padding Attribute, the numbers in the table below represent the minimum version number of the browser that supports this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 4+

Read More

See the following tutorials:CSS Padding,CSS Box Model.

Related Attributes:padding-top,padding-right,padding-bottom,padding-left.