CSS Reference Property

padding-top 5or4t

The padding-top property is used to specify the width of the top area of the element’s padding box. That is, it specifies the area of space required at the top of the element’s content, inside any defined border. c534t

Every element on a web page is rectangular. Each element has a rectangular box model, which describes each of the rectangular boxes (areas) generated for the element: the content box, the padding box, the border box, and the margin box. The content box exists for every element. The padding, border, and margin boxes are optional, and their existence depends on whether you apply a padding, border, or margin to an element.

box-areas
The box model of an element in CSS—includes the content, padding, border, and margin areas.

The padding of an element is usually used to calculate the width and height of an element. The width is usually equal to the width is set to ‘300px’, and the width of its padding (left and right) sums up to ’60px’, then the total computed width of the element is ‘360px’, not ‘300px’. The same reasoning applies to the computed height of the element.

This calculation of the element’s height and width can change when the width property, and its padding width is set to ’60px’, then the total width will remain ‘300px’, and the width of the content area of the element will decrease from ‘300px’ to ‘240px’.

Using box-sizing: border-box; and is now the recommended practice in CSS.

You can read more about this in the box-sizing property entry. Also, see the demo section below for a live example.

Official Syntax 3xs5l

  • Syntax:

    padding-top: <length> | <percentage>
  • Initial: 0
  • Applies To: all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column
  • Animatable: yes, as a length

Values u704t

<length>
See the <length> entry for a list of possible values.
<percentage>
See the <percentage> entry for a list of possible values. A percentage value is calculated with respect to the width of the element’s containing block.

Notes 441w3q

The padding can not be negative. An element can also inherit its padding value from its parent’s using the inherit keyword. For example:

.element {
    padding-top: inherit;
}
                

Examples 2h2053

The following sets the top padding of an element:

.container {
    padding-top: 30px;
}

.container-2 {
    padding-top: 15%;
}

.sub-container {
    padding-top: inherit;
}
                

Browser 572e63

The padding-top property works in all major browsers: Chrome, Firefox, Safari, Opera, Internet Explorer, and on Android and iOS.

Further Reading 4s104w

Written by

Last updated June 3, 2020 at 12:34 pm by Pedro Botelho

Do you have a suggestion, question or want to contribute? Submit an issue.