CSS padding-right Property

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

What You’ll Learn

The padding-right property sets inner spacing on the right edge of an element. It controls spacing inside the box so content does not touch the right border directly.

01

Right 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-right property in CSS is used to define the space between the content of an element and its right border.

This property allows you to control the inner spacing, enhancing the readability and visual appeal of your webpage by ensuring that the content does not touch the borders directly.

Definition and Usage

Apply padding-right when you need extra room to the right of the content inside an element — for example, making room beside a close icon, offsetting text in a toolbar, or adding space inside a card before the right border.

Like all padding properties, padding-right 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-right for inner spacing on the right. Use margin-right when you need space outside the element, between this box and the one to its right.

padding-right → space after content Always the physical right edge

📝 Syntax

The syntax for the padding-right property is straightforward. You can specify the padding using various units like pixels, ems, percentages, and more.

syntax.css
element {
  padding-right: value;
}

Here, value can be a length, percentage, or the keyword auto.

Basic Example

padding-right.css
.box {
  padding-right: 20px;
  border: 1px solid black;
  background-color: lightgray;
}

Syntax Rules

  • Apply padding-right to any element that needs extra inner space on the right side.
  • The value is a length, percentage, or keyword such as inherit or initial.
  • The property is not inherited — child elements do not automatically get the parent’s right padding.
  • Percentage padding is calculated relative to the width of the containing block.

⚡ Quick Reference

QuestionAnswer
Initial value0
Applies toRight padding side only
InheritedNo
AnimatableYes, as a length
Common useCards, toolbars, inputs, and content that needs room before the right border

🎯 Default Value

The default value of the padding-right property is 0, meaning there is no space added to the right side of the element by default.

💎 Property Values

ValueExampleDescription
Lengthpadding-right: 10px;Specifies a fixed padding amount using units like px, em, rem, or cm.
Percentagepadding-right: 10%;Specifies a padding amount as a percentage of the containing element’s width.
initialpadding-right: initial;Sets the property to its default value.
inheritpadding-right: inherit;Inherits the padding value from the parent element.
padding-right: 20px; padding-right: 1.5rem; padding-right: 10%;

👀 Live Preview

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

pr-sm
pr-md
pr-lg
pr-xl

Examples Gallery

Start with the reference box example, try different right values, add trailing spacing in components, and compare physical right padding with logical inline-end padding.

🔢 Basic padding-right

Start with the reference example — right padding on a div with a border and light gray background.

Example 1 — Box with Right Padding

In this example, we’ll add right padding of 20px to a <div> element.

padding-right-example.html
<style>
  .box {
    padding-right: 20px;
    border: 1px solid black;
    background-color: lightgray;
  }
</style>

<div class="box">
  This box has 20px right padding.
</div>
Try It Yourself

How It Works

The light gray background fills the padding area, so the 20px gap appears between the content and the right border. The padding stays inside the border.

Example 2 — Different Right Values

Use rem units for scalable right spacing that grows with root font size.

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

.comfortable {
  padding-right: 1.5rem;
}

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

How It Works

Each class sets a different right padding while leaving the left side unchanged. The background fills the padding area so you can compare the spacing visually.

🛠 Layout Patterns

Apply right padding to components and compare physical vs logical properties.

Example 3 — Alert Bar with Trailing Space

Add right padding so message text does not crowd a dismiss area on the right.

padding-right-alert.css
.alert {
  padding-left: 1rem;
  padding-right: 2.5rem;
  padding-block: 0.75rem;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 0.5rem;
  color: #92400e;
  font-size: 0.875rem;
}
Try It Yourself

How It Works

Extra padding-right reserves space for a close icon or action on the trailing side so text does not overlap it.

Example 4 — Physical vs Logical Right Padding

Compare padding-right with padding-inline-end.

padding-right-logical.css
/* Physical — fixed to right edge */
.physical {
  padding-right: 24px;
}

/* Logical — follows text direction */
.logical {
  padding-inline-end: 24px;
}
Try It Yourself

How It Works

In horizontal LTR English, both approaches look the same. padding-inline-end stays correct when text direction changes to RTL; physical right padding does not.

padding-right vs padding, padding-inline-end & margin-right

The padding shorthand sets padding on all four sides at once. Use padding-right when you need spacing on only the right edge.

padding-inline-end is the logical equivalent that follows the inline axis. Use padding-right for simple physical layouts; prefer padding-inline-end in multilingual or RTL designs. Remember: margin-right adds space outside the border, not inside it.

padding-right-companion.css
/* Right only */
.toolbar {
  padding-right: 1.25rem;
}

/* All four sides via shorthand */
.card {
  padding: 1rem 1.5rem;
}

/* Space to the right outside the border */
.sidebar {
  margin-right: 2rem;
}

♿ Accessibility

  • Improve readability — Text benefits from right padding so content does not crowd the right border or trailing controls.
  • Touch targets — Buttons and dismiss icons need comfortable right padding so text does not overlap them.
  • RTL layouts — For multilingual sites, consider padding-inline-end instead of padding-right so spacing follows text direction.
  • Do not hide content — Very large right padding on small screens can squeeze readable text area.
  • Test zoomed layouts — Users who zoom in rely on comfortable padding to keep text readable.

🧠 How padding-right Works

1

You set a padding value

Write padding-right: 20px; with a length, percentage, or keyword.

CSS rule
2

Browser adds space on the right

Padding is inserted between the content edge and the border on the right 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 right spacing

Content has breathing room after it without affecting spacing on other sides or outside the border.

Browser Compatibility

The padding-right property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera, as well as older browsers. It is a well-established property in the CSS specification, so you can use it confidently across different web projects.

Universal · All browsers

Right padding works everywhere

Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer all support padding-right 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-right property 100% supported

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

Conclusion

The padding-right property is an essential tool in CSS for managing the spacing within elements.

By controlling the right padding, you can create visually appealing layouts and improve the user experience on your website. Experiment with different values and units to see how they impact the appearance and readability of your content.

💡 Best Practices

✅ Do

  • Use padding-right for inner spacing on the right in LTR layouts
  • Prefer rem or em for scalable right spacing
  • Pair with trailing icons or actions that need reserved space
  • Use the padding shorthand when all sides need spacing
  • Consider padding-inline-end for RTL-aware international layouts

❌ Don’t

  • Confuse padding-right with margin-right for outer spacing
  • Use excessive right padding that pushes content off small screens
  • Forget that percentage padding is based on width, not height
  • Rely on padding-right alone in RTL multilingual layouts
  • Use physical right padding when writing-mode-aware layouts need logical properties

Key Takeaways

Knowledge Unlocked

Five things to remember about padding-right

Use these points when spacing content on the right edge.

5
Core concepts
0 02

Default 0

No spacing.

Default
03

Inside Border

Part of box model.

Scope
% 04

Units

px, em, rem, %.

Values
pie 05

Not inline-end

Physical vs logical.

Companion

❓ Frequently Asked Questions

The padding-right property sets inner spacing on the right edge of an element, between the content and the right border. It creates horizontal room after the content inside the element.
The default value is 0, meaning no right inner spacing is applied unless you set padding-right explicitly.
padding-right adds space inside the element, between the content and the border. margin-right adds space outside the border, between this element and the element to its right.
padding-right always targets the physical right edge. padding-inline-end follows the inline axis and stays correct when text direction changes to RTL.
Yes. Percentage padding is calculated relative to the width of the containing block, even for right padding.

Practice in the Live Editor

Open the HTML editor, try different padding-right values, and see how right 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