In this example, we will learn how to set the padding around an element using CSS. We can use the padding-top
, padding-right
, padding-bottom
, and padding-left
properties to set the padding at the top, right, bottom, and left side of the inside element box. We can also use the padding
property as the shorthand property of these properties.
padding-top
propertypadding-right
propertypadding-bottom
propertypadding-left
propertypadding
propertyHTML
<div class="main-element">
This is the main element
</div>
CSS
.main-element{
border: 1px solid black;
padding-top: 10px;
padding-right: 20px;
padding-bottom: 0px;
padding-left: 30px;
}
Output
Here, we used padding-top
to set the padding at the top of the element, padding-right
at the right side of the element, padding-bottom
at the bottom of the element and padding-left
at the left side of the element. We can also use the shorthand padding
property as padding:
In this example, we learned how to set the padding around an element using CSS. We used the padding-top
, padding-right
, padding-bottom
, and padding-left
properties to set the padding at the top, right, bottom, and left side of the inside element box.