The padding-left property in CSS is used to add space between the content and the left border of an element. It helps improve the spacing and appearance of webpage elements.
- It sets the width of the left padding area of an element.
- Padding is the space between the content and the border.
- The value can be defined using units like px, %, or em.
Syntax:
padding-left: length | percentage | initial | inherit;Property values:
- length: This mode is used to specify the size of padding as a fixed value. The default value is 0. It must be non-negative.
- percentage: This mode is used to specify the left padding in percent of the width of the element. It must be non-negative.
- initial: This property is used to set padding-left to its default value. : This property is used to set padding-left to its default value.
Example 1: Here, we are using padding-left: length; property.
<!DOCTYPE html>
<html>
<head>
<title>
padding-left Property
</title>
<style>
.geek {
padding-left: 90px;
color: white;
background: green;
}
</style>
</head>
<body>
<h1 style="color: green;
text-align:center">
GeeksforGeeks
</h1>
<h2 style="text-align:center">
padding-left Property
</h2>
<!-- padding-left property used here -->
<p class="geek">
This paragraph has a padding-left: 90px;
</p>
</body>
</html>
Example 2: Here, we are using padding-left: percentage; property.
<!DOCTYPE html>
<html>
<head>
<title>
padding-left Property
</title>
<style>
.geek {
padding-left: 25%;
color: white;
background: green;
}
</style>
</head>
<body>
<h1 style="color: green;
text-align:center">
GeeksforGeeks
</h1>
<h2 style="text-align:center">
padding-left Property
</h2>
<!-- padding-left property used here -->
<p class="geek">
This paragraph has a padding-left: 25%;
</p>
</body>
</html>