- CSS Padding
- The individual sides
- Example of the individual padding properties:
- Padding as a shorthand property
- Example of the padding shorthand property with one value:
- Example of the padding shorthand property with two values:
- Result
- Example of the padding shorthand property with three values:
- Example of the padding shorthand property with four values:
- Browser support
- Practice Your Knowledge
- padding: 20px 40px 20px 40px is the same with the code above
- CSS Padding
- CSS Padding
- Padding — Individual Sides
- Example
- Padding — Shorthand Property
- Example
- Example
- Example
- Example
- Padding and Element Width
- Example
- Example
- More Examples
- All CSS Padding Properties
- CSS padding-right Property
- Definition and Usage
- Browser Support
- CSS Syntax
- Property Values
- More Examples
- Example
- Example
- Related Pages
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- padding-right
- Syntax
- Values
- Formal syntax
- Examples
- Specifications
- Browser compatibility
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
CSS Padding
The CSS padding property is used for creating space around the content of an element. CSS provides different properties, with the help of which you can set the padding for an element’s each side (right, left, top and bottom).
The individual sides
With the help of the following properties you can set the padding for each side of an element:
As you can guess, for the top, we use padding-top, for bottom padding-bottom, for left side padding-left and right padding-right.
All the padding properties can have the values below:
- length, which is used for specifying a padding in px, pt, cm, etc,
- %, which specifies a padding in % of the width of the containing element,
- inherit , which specifies that the padding must be inherited from its parent element.
Take into account, that CSS padding property cannot accept negative values. Its default value for all padding properties is 0.
Example of the individual padding properties:
html> html> head> title>Title of the document title> style> div < background-color: yellow; padding-top: 50px; padding-right: 30px; padding-bottom: 50px; padding-left: 80px; > style> head> body> h2>Individual padding properties h2> div> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.. div> body> html>
Padding as a shorthand property
The CSS padding property is a shorthand property for the individual padding properties below:
In the cases, when the padding property has only 1 value, for example padding: 35px, all the four paddings are 35px.
Example of the padding shorthand property with one value:
html> html> head> title>Title of the document title> style> div < background-color: green; padding: 35px; > style> head> body> h2>Individual padding properties h2> div> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. div> body> html>
The padding property may have 2 values, for example padding: 20px 40px, where top and bottom paddings are 20px, right and left paddings are 40px.
This is the same with the code above.
p < padding-top: 20px; padding-right: 40px; padding-bottom: 20px; padding-left: 40px; >
Example of the padding shorthand property with two values:
html> html> head> title>Title of the document title> style> p < background-color: #1c87c9; color: white; padding: 20px 40px; > style> head> body> p>Paragraph with background-color, color and padding properties. p> body> html>
Result
The padding property may have 3 values, for example, padding: 20px 15px 35px;, where top padding is 20px, right and left paddings are 15px and bottom padding is 35px.
This is the same with the code above.
p < padding-top: 20px; padding-right: 15px; padding-bottom: 35px; padding-left: 15px; >
Example of the padding shorthand property with three values:
html> html> head> title>Title of the document title> style> div < background-color: lightblue; padding: 20px 15px 35px; > style> head> body> h2>Example of the padding shorthand property h2> div> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. div> body> html>
And finally, the padding property can have four values, for example padding: 25px 50px 75px 100px;, where top padding is 25px, right padding is 50px, bottom padding is 75px and left padding is 100px.
p < padding: 25px 50px 75px 100px; >
Example of the padding shorthand property with four values:
html> html> head> title>Title of the document title> style> div < background-color: #95e5f7; padding: 25px 50px 75px 100px; > style> head> body> h2>Example of the padding shorthand property h2> div> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. div> body> html>
Browser support
Practice Your Knowledge
padding: 20px 40px 20px 40px is the same with the code above
padding-top: 20px; padding-left: 40px; padding-right: 20px; padding-bottom: 40px; padding-top: 20px; padding-bottom: 40px; padding-right: 20px; padding-left: 40px; padding-bottom: 20px; padding-left: 40px; padding-top: 20px; padding-right: 40px;
CSS Padding
Padding is used to create space around an element’s content, inside of any defined borders.
CSS Padding
The CSS padding properties are used to generate space around an element’s content, inside of any defined borders.
With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).
Padding — Individual Sides
CSS has properties for specifying the padding for each side of an element:
All the padding properties can have the following values:
- length — specifies a padding in px, pt, cm, etc.
- % — specifies a padding in % of the width of the containing element
- inherit — specifies that the padding should be inherited from the parent element
Note: Negative values are not allowed.
Example
Set different padding for all four sides of a element:
Padding — Shorthand Property
To shorten the code, it is possible to specify all the padding properties in one property.
The padding property is a shorthand property for the following individual padding properties:
If the padding property has four values:
- padding: 25px 50px 75px 100px;
- top padding is 25px
- right padding is 50px
- bottom padding is 75px
- left padding is 100px
Example
Use the padding shorthand property with four values:
If the padding property has three values:
- padding: 25px 50px 75px;
- top padding is 25px
- right and left paddings are 50px
- bottom padding is 75px
Example
Use the padding shorthand property with three values:
If the padding property has two values:
- padding: 25px 50px;
- top and bottom paddings are 25px
- right and left paddings are 50px
Example
Use the padding shorthand property with two values:
If the padding property has one value:
Example
Use the padding shorthand property with one value:
Padding and Element Width
The CSS width property specifies the width of the element’s content area. The content area is the portion inside the padding, border, and margin of an element (the box model).
So, if an element has a specified width, the padding added to that element will be added to the total width of the element. This is often an undesirable result.
Example
Here, the element is given a width of 300px. However, the actual width of the element will be 350px (300px + 25px of left padding + 25px of right padding):
To keep the width at 300px, no matter the amount of padding, you can use the box-sizing property. This causes the element to maintain its actual width; if you increase the padding, the available content space will decrease.
Example
Use the box-sizing property to keep the width at 300px, no matter the amount of padding:
More Examples
Set the left padding
This example demonstrates how to set the left padding of aelement.
Set the right padding
This example demonstrates how to set the right padding of aelement.
Set the top padding
This example demonstrates how to set the top padding of aelement.
Set the bottom padding
This example demonstrates how to set the bottom padding of aelement.
All CSS Padding Properties
Property Description padding A shorthand property for setting all the padding properties in one declaration padding-bottom Sets the bottom padding of an element padding-left Sets the left padding of an element padding-right Sets the right padding of an element padding-top Sets the top padding of an element CSS padding-right Property
Set the right padding for a
element to 150 pixels:
More «Try it Yourself» examples below.
Definition and Usage
An element’s padding is the space between its content and its border.
The padding-right property sets the right padding (space) of an element.
Note: Negative values are not allowed.
Default value: 0 Inherited: no Animatable: yes. Read about animatable Try it Version: CSS1 JavaScript syntax: object.style.paddingRight=»50px» Try it Browser Support
The numbers in the table specify the first browser version that fully supports the property.
CSS Syntax
Property Values
Value Description Demo length Specifies a fixed right padding in px, pt, cm, etc. Default value is 0. Read about length units Demo ❯ % Specifies a right padding in percent of the width of the containing element Demo ❯ initial Sets this property to its default value. Read about initial inherit Inherits this property from its parent element. Read about inherit More Examples
Example
Set the right padding for a
element to 50% of the width of the containing element:
Example
Set the right padding for a
element to 2 em:
Related Pages
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
padding-right
CSS свойство padding-right элемента устанавливает значение поля от правого края элемента. Поля элемента (padding area) это область, расположенная между контентом и границей элемента. Отрицательное значение не валидно.
Начальное значение 0 Применяется к все элементы, кроме table-row-group , table-header-group , table-footer-group , table-row , table-column-group и table-column . Это также применяется к ::first-letter и ::first-line . Наследуется нет Проценты ссылается на ширину содержащего блока Обработка значения процент, как указан, или абсолютная длина Animation type длина Syntax
/* значения */ padding-right: 0.5em; padding-right: 0; padding-right: 2cm; /* значения */ padding-right: 10%; /* Общие значения */ padding-right: inherit; padding-right: initial; padding-right: unset;
Values
Устанавливает положительную фиксированную ширину. Подробнее: .
Процент по отношению к ширине контейнера.
Formal syntax
Examples
.content padding-right: 5%; > .sidebox padding-right: 10px; >
Specifications
Specification Status Comment CSS Box Model
Определение ‘padding-right’ в этой спецификации.Кандидат в рекомендации Без изменений. CSS Transitions
Определение ‘padding-right’ в этой спецификации.Рабочий черновик Определяет padding-right , как анимируемое свойство. CSS Level 2 (Revision 1)
Определение ‘padding-right’ в этой спецификации.Рекомендация Без изменений. CSS Level 1
Определение ‘padding-right’ в этой спецификации.Рекомендация Исходное определение. Browser compatibility
BCD tables only load in the browser
Found a content problem with this page?
This page was last modified on 7 нояб. 2022 г. by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.