The padding-top property sets inner spacing on the top edge of an element. Padding is the space between the content and the border, and top padding gives content breathing room between the top border and the text or media inside the box.
The padding-top property in CSS is used to define the space between the content of an element and its top border. It is a crucial property for managing the spacing and layout of elements within a webpage.
The padding-top property allows you to control the vertical spacing within an element, providing a way to create visual separation and layout consistency.
Definition and Usage
Apply padding-top when you need extra room above the content inside an element — for example, below a heading in a card, above a button in a toolbar, or at the top of a content block below the top border.
Like all padding properties, padding-top increases the visible size of an element’s background and border box. It never collapses and always stays inside the element’s border.
💡
Beginner Tip
Use padding-top for inner spacing above content. Use margin-top when you need space outside the element, between this box and the one above it.
padding-top → space above contentAlways the physical top edge
Foundation
📝 Syntax
The syntax for the padding-top property is simple. You can specify the padding using various units, including pixels, ems, percentages, and more.
syntax.css
element{padding-top:value;}
Here, value can be a length (e.g., px, em, rem), a percentage (%), or the keyword auto.
Four boxes with the same content and different pt- utility classes showing increasing top inner spacing:
pt-sm
pt-md
pt-lg
pt-xl
Hands-On
Examples Gallery
Start with the reference box example, try different top values, add spacing in stacked layouts, and compare physical top padding with logical block-start padding.
🔢 Basic padding-top
Start with the reference example — top padding on a div with a light blue background.
Example 1 — Div with Custom Top Padding
In this example, we’ll add top padding of 20 pixels to a <div> element.
padding-top-example.html
<style>.example{padding-top:20px;background-color:lightblue;}</style><divclass="example">
This div has 20 pixels of padding at the top.
</div>
The .example class applies a top padding of 20px, creating space between the content and the top edge of the div. The light blue background fills the padding area so you can see the gap.
Example 2 — Different Top Values
Use rem units for scalable top spacing that grows with root font size.
Each class sets a different top padding while leaving the bottom and sides unchanged. The background fills the padding area so you can compare the spacing visually.
🛠 Layout Patterns
Apply top padding to cards and compare physical vs logical properties.
Example 3 — Card Header Spacing
Add top padding to a card body so content does not crowd the top border or header area.
Card body with extra top padding for comfortable reading below the top edge.
How It Works
Extra padding-top gives the first line of text more room below the card’s top edge. This is a common pattern when the top border or header sits close to the content.
Example 4 — Physical vs Logical Top Padding
Compare padding-top with padding-block-start.
padding-top-logical.css
/* Physical — fixed to top edge */.physical{padding-top:24px;}/* Logical — follows writing mode */.logical{padding-block-start:24px;}
In horizontal English layouts, both approaches look the same. padding-block-start stays correct when writing mode changes; physical top padding does not.
Companion
padding-top vs padding, padding-block-start & margin-top
The padding shorthand sets padding on all four sides at once. Use padding-top when you need spacing on only the top edge.
padding-block-start is the logical equivalent that follows the block axis. Use padding-top for simple physical layouts; prefer padding-block-start in multilingual or vertical writing-mode designs. Remember: margin-top adds space outside the border, not inside it.
padding-top-companion.css
/* Bottom only */.card-body{padding-top:1.25rem;}/* All four sides via shorthand */.section{padding:1rem2rem;}/* Space above the element (outside border) */.article{margin-top:2rem;}
A11y
♿ Accessibility
Improve readability — Paragraphs and card content benefit from top padding so text does not crowd the top border.
Touch targets — Buttons and links inside padded containers are easier to tap when top padding gives them room.
Do not hide content — Very large top padding on small screens can push important content out of view.
Keep focus visible — Padding adjusts inner spacing; it should not replace visible focus outlines on interactive elements.
Test zoomed layouts — Users who zoom in rely on comfortable padding to keep text readable.
🧠 How padding-top Works
1
You set a padding value
Write padding-top: 20px; with a length, percentage, or auto.
CSS rule
2
Browser adds space on the top
Padding is inserted between the content edge and the border on the top side only.
Box model
3
Background fills the padding area
The element’s background color and background image extend into the padding box, making the gap visible.
Rendering
=
▦
Comfortable top spacing
Content has breathing room above it without affecting spacing on other sides or outside the border.
Compatibility
Browser Compatibility
The padding-top property is widely supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. This makes it a reliable property for ensuring consistent spacing across different devices and browsers.
✓ Universal · All browsers
Top padding works everywhere
Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer all support padding-top as a core box-model property.
100%Universal support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Legacy & Chromium
Full support
OperaAll versions
Full support
padding-top property100% supported
Bottom line:padding-top is one of the most reliable CSS properties. Safe to use in any project without fallbacks.
Wrap Up
Conclusion
The padding-top property is an essential tool for web developers to control the spacing of elements within a webpage.
By adjusting the top padding, you can create a more organized and visually pleasing layout. Experiment with different padding values and units to see how this property can enhance your web design.
Pair with padding-bottom for asymmetric vertical rhythm
Use the padding shorthand when all sides need spacing
Test on mobile to ensure top padding does not waste screen space
❌ Don’t
Confuse padding-top with margin-top for outer spacing
Use excessive top padding that pushes content off small screens
Forget that percentage padding is based on width, not height
Assume auto is useful for padding (it rarely is)
Use physical top padding when writing-mode-aware layouts need padding-block-start
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about padding-top
Use these points when spacing content on the top edge.
5
Core concepts
↑01
Top Only
One physical edge.
Purpose
002
Default 0
No spacing.
Default
▦03
Inside Border
Part of box model.
Scope
%04
Units
px, em, rem, %, auto.
Values
pbs05
Not block-start
Physical vs logical.
Companion
❓ Frequently Asked Questions
The padding-top property sets inner spacing on the top edge of an element, between the content and the top border. It creates vertical room above the content inside the element.
The default value is 0, meaning no top inner spacing is applied unless you set padding-top explicitly.
padding-top adds space inside the element, between the content and the border. margin-top adds space outside the border, between this element and the element above it.
padding-top always targets the physical top edge. padding-block-start follows the block axis and stays correct when the writing mode changes, such as in vertical text layouts.
Yes. Percentage padding is calculated relative to the width of the containing block, even for top padding.