CSS padding-top Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Box Model & Spacing

What You’ll Learn

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.

01

Bottom Edge Only

One physical side.

02

Syntax

Single value.

03

Units

px, em, rem, %.

04

Box Model

Inside the border.

05

Default 0

No spacing by default.

06

padding

Four-side shorthand.

Introduction

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 content Always the physical top edge

📝 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.

Basic Example

padding-top.css
.example {
  padding-top: 20px;
  background-color: lightblue;
}

Syntax Rules

  • Apply padding-top to any element that needs extra inner space above its content.
  • The value is a length, percentage, or auto.
  • The property is not inherited — child elements do not automatically get the parent’s top padding.
  • Percentage padding is calculated relative to the width of the containing block.

⚡ Quick Reference

QuestionAnswer
Initial value0
Applies toTop padding side only
InheritedNo
AnimatableYes, as a length
Common useCards, paragraphs, buttons, and any content that needs room below the top border

🎯 Default Value

The default value of the padding-top property is 0. This means that if no value is specified, there will be no padding at the top of the element.

💎 Property Values

ValueExampleDescription
Lengthpadding-top: 10px;Specifies the top padding in fixed units such as px, em, or rem.
Percentagepadding-top: 5%;Specifies the top padding as a percentage of the containing element’s width.
autopadding-top: auto;Allows the browser to calculate the top padding automatically. This value is rarely used with padding properties.
initialpadding-top: initial;Resets to the initial value (0).
inheritpadding-top: inherit;Inherits the value from the parent element.
padding-top: 20px; padding-top: 1.5rem; padding-top: 5%;

👀 Live Preview

Four boxes with the same content and different pt- utility classes showing increasing top inner spacing:

pt-sm
pt-md
pt-lg
pt-xl

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>

<div class="example">
  This div has 20 pixels of padding at the top.
</div>
Try It Yourself

How It Works

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.

padding-top-rem.css
.compact {
  padding-top: 0.5rem;
}

.comfortable {
  padding-top: 1.5rem;
}

.spacious {
  padding-top: 2.5rem;
}
Try It Yourself

How It Works

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.

padding-top-card.css
.card-body {
  padding-inline: 1.25rem;
  padding-top: 1.75rem;
  padding-bottom: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
}
Try It Yourself

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;
}
Try It Yourself

How It Works

In horizontal English layouts, both approaches look the same. padding-block-start stays correct when writing mode changes; physical top padding does not.

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: 1rem 2rem;
}

/* Space above the element (outside border) */
.article {
  margin-top: 2rem;
}

♿ 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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Legacy & Chromium
Full support
Opera All versions
Full support
padding-top property 100% supported

Bottom line: padding-top is one of the most reliable CSS properties. Safe to use in any project without fallbacks.

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.

💡 Best Practices

✅ Do

  • Use padding-top for inner spacing above content
  • Prefer rem or em for scalable top spacing
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about padding-top

Use these points when spacing content on the top edge.

5
Core concepts
0 02

Default 0

No spacing.

Default
03

Inside Border

Part of box model.

Scope
% 04

Units

px, em, rem, %, auto.

Values
pbs 05

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.

Practice in the Live Editor

Open the HTML editor, try different padding-top values, and see how top spacing changes your layout instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful