Property | Description |
---|---|
padding | It is used to set all the padding properties in one declaration. |
padding-left | It is used to set the left padding of an element. |
padding-right | It is used to set the right padding of an element. |
padding-top | It is used to set top padding of an element. |
padding-bottom | It is used to set the bottom padding of an element. |
These are some possible values for margin property.
Value | Description |
---|---|
length | It is used to define fixed padding in pt, px, em etc. |
% | It defines padding in % of containing elements. |
<!DOCTYPE html>
<html>
<head>
<style>
p {
background-color: green;
}
p.ex {
padding-top: 100px;
padding-bottom: 100px;
padding-right: 150px;
padding-left: 150px;
}
</style>
</head>
<body>
<p>This paragraph is not displayed with specified padding. </p>
<p class="ex">This paragraph is displayed with specified padding.</p>
</body>
</html>
To minimize the code, it is possible in CSS to specify all the padding properties in one property.
The padding property is a shorthand property for the following individual
So, here is how it works:
If the padding property has four values:
<!DOCTYPE html>
<html>
<head>
<style>
p {
background-color: yellow;
}
p.ex {
padding: 50px 100px 50px 100px;
}
</style>
</head>
<body>
<p>This paragraph is not displayed with specified padding. </p>
<p class="ex">This paragraph is displayed with specified padding.</p>
</body>
</html>
If the padding property has two values:
<!DOCTYPE html>
<html>
<head>
<style>
p {
background-color: pink;
}
p.ex {
padding: 50px 100px;
}
</style>
</head>
<body>
<p>This paragraph is not displayed with specified padding. </p>
<p class="ex">This paragraph is displayed with specified padding.</p>
</body>
</html>
If the padding property has one value:
padding: 100px;
all four padding are 100px
<!DOCTYPE html>
<html>
<head>
<style>
p {
background-color: Lightgreen;
}
p.ex {
padding: 50px;
}
</style>
</head>
<body>
<p>This paragraph is not displayed with specified padding. </p>
<p class="ex">This paragraph is displayed with specified padding.</p>
</body>
</html>