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

CSS Reference Manual

CSS @rules (RULES)

Complete List of CSS Properties

CSS padding-Usage and example of top attribute

padding-The top CSS property sets the padding at the top side, that is, the space between the top boundary and the content of an element. However, in many cases, the shorthand notation CSS propertypaddingEasier to use and more desirable.

The following table provides usage instructions and version history of this attribute, as well as its usage syntax 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
Can be animated:Yes.Please refer to Animation properties.
Version:CSS 1,2,3
JavaScript syntax:object.style.paddingTop="2cm"

padding-The syntax of top

The syntax of this attribute is as follows:

padding-top: length | percentage | initial | inherit

The following examples demonstrate how to use padding-top attribute.

  h1 {
   padding-top: 2em;
  }
  p {
   padding-top: 50px;
  }
Test and see‹/›

Attribute value

The following table describes the value of this attribute.

ValueDescription
lengthValues in units such as px, pt, cm, em, etc., negative values are not allowed.
percentageSpecify percentage padding. The percentage is calculated relative to the width of the element's containing block. Negative percentage values are not allowed.
initialSet this property to its default value.
inheritIf specified, the associated element uses its parent element padding-The value of the top attribute.

Browser compatibility

padding-Browser compatibility of the top 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 properties:padding,padding-right,padding-bottom,padding-left.