- padding
- Синтаксис
- Значения
- 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 Property
- Definition and Usage
- Browser Support
- CSS Syntax
- Property Values
- More Examples
- Example
- Example
- Example
- HTML Padding
- How does Padding work in HTML?
- 4 Padding Values
- Examples of HTML Padding
- Example #1
- Example #2
- Example #3
- Conclusion
- Recommended Articles
padding
Свойство padding устанавливает внутренние отступы/поля со всех сторон элемента. Область отступов это пространство между содержанием элемента и его границей. Отрицательные значения не допускаются.
Свойство padding краткая форма записи свойств, чтобы не писать отдельное правило для каждой стороны ( padding-top , padding-right , padding-bottom , padding-left ).
- padding-bottom (en-US): 0
- padding-left : 0
- padding-right : 0
- padding-top (en-US): 0
- padding-bottom (en-US): процент, как указан, или абсолютная длина
- padding-left : процент, как указан, или абсолютная длина
- padding-right : процент, как указан, или абсолютная длина
- padding-top (en-US): процент, как указан, или абсолютная длина
Синтаксис
/* Применяется для всех 4 сторон */ padding: 1em; /* По вертикали | По горизонтали */ padding: 5% 10%; /* Сверху | По горизонтали | Снизу */ padding: 1em 2em 2em; /* Сверху | Справа | Снизу | Слева */ padding: 2px 1em 0 1em; /* Глобальные значения */ padding: inherit; padding: initial; padding: unset;
Значения
Укажите одно, два, три или четыре следующих значения:
Устанавливает неотрицательный, фиксированный размер. Подробнее в разделе .
Относительно ширины родительского блока.
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 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:
HTML Padding
Generally, Padding is the space between the things for anything, the same as in the HTML refers to the space between the HTML contents and its borders. The HTML padding is also a property for using the web pages more attractively and highlighting the websites. It also some types like padding-top, padding-left, padding-right, padding-bottom, etc. We can align the words or text in similar type padding formats. The Padding creates extra spaces within the HTML elements, and the also margin creates extra space for the HTML elements. We also use the CSS styles and their properties for all the padding areas.
Web development, programming languages, Software testing & others
Each HTML tag has its attributes and properties of the elements. Likewise, syntax also differs, and they will use for all of the other HTML tags if the user requirements need. Below is the basic syntax of the padding elements in HTML.
The above syntax helps create the sample web page and will use the padding styles in the CSS styles for the head section in HTML. Based on that, the syntax will vary if we use it in the other sections and tags in the HTML.
How does Padding work in HTML?
Compared to margin, Padding is the extra space created inside some HTML elements, but the margin is made outside the HTML elements. Each element, like Padding and margin, refers to the box models that are Padding, margins, and borders all combined with the box models of the HTML containers. In that model, the middle portions of the areas used for HTML content, that is, text or images, videos, etc., surround with some padding, margins, and borders if the user needs customized development in the web pages.
We won’t use all these as necessary, but it’s beneficial to remember the box model is applied to every tag or element on the web pages. Some CSS styles and properties allow a string of values that is replaced with the number of properties, and they are represented with values separated by using spaces.
The Padding in the box with inside margins and borders areas and outside the HTML contents area, padding property, is used to specify the uniform padding style in the box container. Three or foursome values are specified independently based on our declaration in the codes with client requirements.
When calculating the lengths for Padding, there are certain permissible values to consider, ensuring they are not negative; also, calculate the percentage that includes the box width and height and does not have the negative values. We can use Padding on the image side for the web pages in HTML with the help of creating buffers between the images and the data streams like HTML content. It gives the images like little breathing room, so they aren’t jammed in either text or other images.
We typically position the images on the left side of the web pages, closely attaching the data content. There is no distractingly close to the pictures. Still, when using the same images in the right panel, the Padding creates a buffer between the images and the text; it will be helpful for a pleasant reading experience from the user’s perspective. We can also add Padding in the image canvas using edit operations like an HTML editor with some style attributes and switch to the rich text editors after the user selects the images.
We add selective Padding, such as a 10-pixel border, to all sides of the images that we select or upload as image contents to the web pages based on user or client instructions; also, we can add the Padding selectively by using some padding styles like the padding-bottom option to padding-right based on the user requirements.
4 Padding Values
We can use Padding in javascript functions to create and resize the border styles or padding styles automatically after calling the javascript functions in the HTML codes. Generally, the padding property sets or returns the Padding of the HTML elements that the property takes from a single value up to four values; we will discuss each padding value below.
- Single value: Example like div-all four sides of the HTML contents will have a padding value like 12 px.
- Two values: div-the top and bottom Padding will be 12px, and the left and right paddings will be 13px.
- Three values: div-the top Padding will be 10px, the left and right Padding will be 13px, and the bottom Padding will be 14px.
- Four values: div-top Padding is 12px, right Padding is 13px, bottom Padding is 14px, and the left Padding will be 15px.
Examples of HTML Padding
The examples of HTML Padding are given below:
Example #1
.sample < border: 2px solid green; padding: 34px; >.sample2
Welcome To My Domain
Welcome To My Domain
WelcomeTo My Domain User!
Example #2
.sample < border: 2px solid green; padding: 34px; >.sample2
Welcome To My Domain
Welcome To My Domain
WelcomeTo My Domain User!
Example #3
#sample < border: 2px solid green; padding: 34px; >.sample2
Welcome
function samples()The first example illustrates the fundamental concept of Padding. In the second example, we incorporate additional images into the web pages using padding styles. The final example is using javascript functions to set or resize the padding styles automatically.
Conclusion
We already discussed some HTML concepts in real-time scenarios, whichever we are using HTML tags in web pages, not only in web mode but also on user compatibility; it will accept the mobile (both android and ios) modes based on user requirements.
Recommended Articles
This is a guide to HTML Padding. Here we discuss the basic concept, how Padding works in HTML, and the respective examples. You can also go through our other related articles to learn more –
89+ Hours of HD Videos
13 Courses
3 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.597+ Hours of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5HTML & CSS Course Bundle — 33 Courses in 1 | 9 Mock Tests
125+ Hours of HD Videos
33 Courses
9 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5