The Wayback Machine - https://web.archive.org/web/20241222220542/https://www.geeksforgeeks.org/css-padding-right-property/
Open In App

CSS padding-right Property

Last Updated : 28 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Padding is the space between its content and its border. The padding-right property in CSS is used to set the width of the padding area on the right of an element.

Syntax: 

padding-right: length | percentage | initial | inherit;

Property values: 

  • length: This mode is used to specify the size of padding as a fixed value. The default value is 0. It must be non-negative.
  • percentage: This mode is used to set the right padding in percent of the width of the element. It must be non-negative.
  • initial: This property is used to set the default value.

Example: In this example, we use padding-right: length; property.

html
<!DOCTYPE html>
<html>
<head>
    <title>
        padding-right Property
    </title>

    <style>
        .geek {
            padding-right: 200px;
            color: white;
            background: green;
            width: 50%;
            font-size: 18px;
        }
    </style>
</head>

<body style="text-align:center">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>

    <h2>
        padding-right Property
    </h2>

    <!-- padding-right property used here -->
    <p class="geek">
        This paragraph has a padding-right: 200px;
    </p>
</body>
</html>

Output: 

paddingright

Example:  In this example, we are using padding-right: percentage; property.

html
<!DOCTYPE html>
<html>
<head>
    <title>
        padding-right Property
    </title>
    <style>
        .geek {
            padding-right: 40%;
            color: white;
            background: green;
            width: 50%;
            font-size: 18px;
        }
    </style>
</head>

<body style="text-align:center">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h2>
        padding-right Property
    </h2>

    <!-- padding-right property used here -->
    <p class="geek">
        This paragraph has a padding-right: 40%;
    </p>
</body>
</html>

Output: 

paddingright

Example: In this example, we are using padding-right: initial; property.

html
<!DOCTYPE html>
<html>
<head>
    <title>
        padding-right Property
    </title>

    <style>
        .geek {
            padding-right: initial;
            color: white;
            background: green;
            width: 70%;
            font-size: 25px;
        }
    </style>
</head>

<body style="text-align:center">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>

    <h2>
        padding-right Property
    </h2>

    <!-- padding-right property used here -->
    <p class="geek">
        This paragraph has a padding-right: initial;
    </p>
</body>
</html>

Output: 

Supported Browsers: The browser supported by padding-right property are listed below: 

  • Google Chrome 1.0 and above
  • Edge 12.0 and above
  • Internet Explorer 4.0 and above
  • Firefox 1.0 and above
  • Opera 3.5 and above
  • Apple Safari 1.0 and above

CSS padding-right Property – FAQs

What is the function of the padding-right property in CSS?

The padding-right property in CSS sets the space between the content of an element and its right edge. It adds internal spacing on the right side, enhancing the layout structure and visual balance.

How do I apply 10px padding on the right side of an element?

You can apply 10px padding on the right side using: padding-right: 10px; . This creates a 10-pixel space between the content and the right border of the element.

Does padding-right affect the overall width of a block-level element?

Yes, padding-right affects the total width of a block-level element by adding space to the right side within the element’s box model, unless the box-sizing is set to “border-box.”

Can I use negative values with padding-right?

No, padding-right does not accept negative values. It only takes positive lengths or zero.

How does padding-right relate to text-overflow settings?

Padding-right can influence the appearance of text-overflow, especially when using properties like ellipsis or clipping. The padding space affects where the overflow occurs.



Next Article

Similar Reads

three90RightbarBannerImg