- CSS padding Property
- Definition and Usage
- Browser Support
- CSS Syntax
- Property Values
- More Examples
- Example
- Example
- Example
- padding
- Аргументы
- padding
- Try it
- Constituent properties
- Syntax
- Values
- Formal definition
- Formal syntax
- padding-right
- Syntax
- Values
- Formal syntax
- Examples
- Specifications
- Browser compatibility
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- HTML Padding – CSS Padding Order
- What is padding in CSS?
- Padding-top property
- Padding-right property
- Padding-bottom property
- Padding-left property
- Difference between Padding and Margin in CSS
- Padding Shorthand Property
- Conclusion
CSS padding Property
Set the padding for all four sides of a
element to 35 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 property is a shorthand property for:
Note: Padding creates extra space within an element, while margin creates extra space around an element.
This property can have from one to four values.
If the padding property has four values:
- padding:10px 5px 15px 20px;
- top padding is 10px
- right padding is 5px
- bottom padding is 15px
- left padding is 20px
If the padding property has three values:
- padding:10px 5px 15px;
- top padding is 10px
- right and left padding are 5px
- bottom padding is 15px
If the padding property has two values:
If the padding property has one value:
Note: Negative values are not allowed.
Default value: 0 Inherited: no Animatable: yes, see individual properties. Read about animatable Try it Version: CSS1 JavaScript syntax: object.style.padding=»100px 20px» 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 the padding in px, pt, cm, etc. Default value is 0. Read about length units Demo ❯ % Specifies the 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 padding for a
element to 35 pixels for top and bottom, and to 70 pixels for right and left:
Example
Set the padding for a
element to 35 pixels for top, 70 pixels for right and left, and to 50 pixels for bottom:
Example
Set the padding for a
element to 35 pixels for top, 70 pixels for right, 50 pixels for bottom, and to 90 pixels for left:
padding
Свойство padding задает все свойства полей в одной строке. Это свойство может иметь от одного до четырех значений.
* padding:10px 5px 15px 20px; — верхнее поле 10px — правое поле 5px — нижнее поле 15px — левое поле 20px
* padding:10px 5px 15px; — верхнее поле 10px — правое и левое поля 5px — нижнее поле 15px
* padding:10px 5px; — верхнее и нижнее поля 10px — правое и левое поля 5px
* padding:10px; — все четыре поля 10px
Примечание: негативные значения не разрешены.
Значение по умолчанию: 0 Наследуется: нет Версия: CSS1 Аргументы
Значение Описание значение Определяет поле в пикселях или других единицах измерения CSS % Определяет поле в % отношении inherit Значение должно быть унаследовано от элемента родителя padding
The padding CSS shorthand property sets the padding area on all four sides of an element at once.
Try it
An element’s padding area is the space between its content and its border.
Note: Padding creates extra space within an element. In contrast, margin creates extra space around an element.
Constituent properties
This property is a shorthand for the following CSS properties:
Syntax
/* Apply to all four sides */ padding: 1em; /* top and bottom | left and right */ padding: 5% 10%; /* top | left and right | bottom */ padding: 1em 2em 2em; /* top | right | bottom | left */ padding: 5px 1em 0 2em; /* Global values */ padding: inherit; padding: initial; padding: revert; padding: revert-layer; padding: unset;
The padding property may be specified using one, two, three, or four values. Each value is a or a . Negative values are invalid.
- When one value is specified, it applies the same padding to all four sides.
- When two values are specified, the first padding applies to the top and bottom, the second to the left and right.
- When three values are specified, the first padding applies to the top, the second to the right and left, the third to the bottom.
- When four values are specified, the paddings apply to the top, right, bottom, and left in that order (clockwise).
Values
The size of the padding as a fixed value.
The size of the padding as a percentage, relative to the inline size (width in a horizontal language, defined by writing-mode ) of the containing block.
Formal definition
- padding-bottom : 0
- padding-left : 0
- padding-right : 0
- padding-top : 0
- padding-bottom : the percentage as specified or the absolute length
- padding-left : the percentage as specified or the absolute length
- padding-right : the percentage as specified or the absolute length
- padding-top : the percentage as specified or the absolute length
Formal syntax
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.HTML Padding – CSS Padding Order
In this article, we are going to learn about CSS padding properties, the shorthand property, and how padding differs from margin.
What is padding in CSS?
CSS padding creates space around the element’s content. This space is within the element’s border and margin.
Let’s take a look at the CSS box model to better understand how padding works. Every HTML element has a box around it and is comprised of four parts: content, padding, border, and margin.
The blue section is the element’s content while the green section represents the padding. Notice how the padding is inside the border and margin properties.
Let’s look at CSS’s padding properties in more detail.
Padding-top property
This is a CSS property that adds space to the top of an element.
Padding-right property
This is a CSS property that adds space to the right of an element.
Padding-bottom property
This is a CSS property that adds space to the bottom of an element.
Padding-left property
This is a CSS property that adds space to the left of an element.
Difference between Padding and Margin in CSS
Margin creates space around the element and outside its border.
This example adds 50px of margin-bottom to the h1 element. This creates extra space between the h1 and p elements.
Padding Shorthand Property
The padding shorthand property allows us to set the padding on all four sides at once instead writing out padding-top , padding-right , padding-bottom , padding-left .
When you just use one value, equal amounts of padding will be applied on all sides.
Here is the code without the shorthand property:
padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px;
This is what the result would look like in the browser.
When you use two values, the first value adds padding to the top and bottom while the second value adds padding to the left and right.
Here is the code without the shorthand property:
padding-top: 10px; padding-right: 30px; padding-bottom: 10px; padding-left: 30px;
When you use three values, the first value adds padding to the top, the second value adds padding to the right and left, and the third value adds padding to the bottom.
Here is the code without the shorthand property:
padding-top: 10px; padding-right: 30px; padding-bottom: 50px; padding-left: 30px;
And when you use four values, the first value adds padding to the top, the second value adds padding to the right, the third value adds padding to the bottom and the fourth value adds padding to the left.
The best way to remember the order for all four values is to think clockwise (top, right, bottom, left).
padding: 10px 20px 30px 40px;
Here is the code without the shorthand property:
padding-top: 10px; padding-right: 20px; padding-bottom: 30px; padding-left: 40px;
You can choose to use pixels, em, rem or percentages for the values. But you are not allowed to use negative values.
Conclusion
When you want to add space around an HTML element’s content then you’ll use the padding properties.
The padding shorthand property allows us to set the padding on all four sides at once instead writing out padding-top , padding-right , padding-bottom , padding-left .
If you want to create space between elements, then you use the margin properties. With margin you can use negative values whereas with padding that is not allowed.