W3docs

CSS padding-right Property

How to use CSS padding-right property to define the padding space on the right of an element. See property values and examples.

The padding-right CSS property sets the width of the padding area on the right side of an element. Padding is the transparent space between an element's content and its border, so increasing padding-right pushes the right border further away from the content (the content itself stays in place; the element grows wider unless box-sizing is set to border-box).

This page covers the accepted values (lengths, percentages, and the CSS-wide keywords), how percentage padding is calculated, and runnable examples for each case. To set the right padding alone use padding-right; to set all four sides at once use the padding shorthand.

Info

Negative values are not valid.

Info

This property doesn't have any effect on inline elements, like <span>.

Initial Value0
Applies toAll elements. An exception is made when the display property is set to table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column. It also applies to ::first-letter.
InheritedNo.
AnimatableYes. Padding space is animatable.
VersionCSS1
DOM Syntaxobject.style.paddingRight = "40px";
Tip

With the help of the padding property you can set paddings on all the sides of an element with a single announcement.

Syntax

Syntax of CSS padding-right Property

padding-right: length | initial | inherit;

Example of the padding-right property:

Example of CSS padding-right Property with px value

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p {
        border: 2px solid #000;
        color: #8ebf42;
        padding-right: 100px;
      }
    </style>
  </head>
  <body>
    <h2>Padding-right property example</h2>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s...</p>
  </body>
</html>

Result

CSS padding-right Property

Example of the padding-right property with the "length" value:

Example of CSS padding-right Property with pt value

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p {
        border: 2px solid #000;
        color: #8ebf42;
        padding-right: 100pt;
      }
    </style>
  </head>
  <body>
    <h2>Padding-right property example</h2>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
  </body>
</html>

Example of the padding-right property specified in percentage:

Example of CSS padding-right property with % value:

A percentage value is resolved against the width of the element's containing block, not its height. This means right padding scales as the layout gets wider or narrower, which is useful for fluid, responsive spacing.

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p {
        border: 3px solid #cccccc;
        color: deepskyblue;
        padding: 15px;
        padding-right: 10%;
      }
    </style>
  </head>
  <body>
    <h2>Padding-right property example</h2>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
    </p>
  </body>
</html>

Values

ValueDescriptionPlay it
lengthIt sets the right padding in px, pt, cm, etc. Its default value is 0px.Play it »
%It sets right padding in percent of the width of the containing element.Play it »
initialMakes the property use its default value.Play it »
inheritInherits the property from its parents element.

When to use padding-right

Reach for padding-right when you need space only on the right edge of a box — for example, to keep text clear of a trailing icon, to leave room for a scrollbar, or to balance asymmetric spacing in a card. If you need equal spacing on every side, prefer the padding shorthand; if you need the gap outside the border instead of inside it, use margin-right.

A few things worth remembering:

  • Padding is part of the clickable / background area. The element's background color and background image extend through the padding, unlike margin.
  • Negative values are invalid. To pull content the other way, use a negative margin instead.
  • It widens the box by default. With the standard content-box model, padding-right adds to the element's total width. Set box-sizing: border-box to keep the declared width fixed and absorb the padding inward.

Practice

Practice
What is the function of the padding-right property in CSS?
What is the function of the padding-right property in CSS?
Was this page helpful?