CSS Reference ยท Box Model and Sizing
The padding-top property
Reference for the CSS padding-top property: syntax, values, percentages, interaction with box-sizing, examples and browser support.
The padding-top property sets the space between an element's content and its top border. The background of the element fills this space, so it is part of the visible box.
CSS
.banner { padding-top: 3rem; }
Try it
Syntax
CSS
padding-top: <length> | <percentage>
- Initial value:
0 - Applies to: all elements except internal table row groups, header groups, footer groups, rows and column groups
- Inherited: no
- Percentages: relative to the width of the containing block
- Animatable: yes
- Computed value: the percentage as specified or the absolute length
Values
| Value | Description |
|---|---|
<length> |
A fixed size such as 16px or 2rem. Must not be negative. |
<percentage> |
A share of the containing block's width (not height). |
Usage notes
- Total height. With
box-sizing: content-box, top padding adds to the element's rendered height; withborder-box, it is carved out of theheightyou set. - Percentage trick.
padding-top: 56.25%on an empty box produces a 16:9 shape, because the percentage is relative to width.aspect-ratiois the clearer modern way. - Not collapsing. Padding never collapses, unlike
margin-top. Use padding on a parent to stop its first child's margin from collapsing through. - Inline elements. Top padding paints the background above the text but does not move the surrounding lines.
- Fixed headers. Content under a
position: fixedheader often needspadding-top(orscroll-padding-topfor anchors) equal to the header height.
Browser support
Supported in every browser.
Related
paddingโ the shorthandpadding-right,padding-bottom,padding-leftmargin-top- Lesson: Padding