The padding-top property in CSS is used to add space between the content and the top border of an element. Padding helps improve the appearance and readability of webpage elements.
- It sets the width of the top padding area of an element.
- Padding is the space between the content and the border.
- The value can be specified using units like px, %, or em.
Syntax:
padding-top: length | percentage | initial | inherit;Property Values:
- length: This mode is used to specify the size of padding as a fixed value. The size can be set in form of px, cm etc. The default value is 0. It must be non-negative.
- percentage: This mode is used to set the top padding in percentage of the width of the element. It must be non-negative.
- initial: It is used to set the padding-top property to its default value.
- inherit: It is used to inherit the padding-top property from its parent element.
Example: Here, we are using padding-top: length; property.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>
padding-top Property
</title>
<!--Driver Code Ends-->
<style>
.geek {
padding-top: 100px;
width: 50%;
font-size: 18px;
border: 1px solid black;
}
</style>
<!--Driver Code Starts-->
</head>
<body>
<h2>
padding-top Property
</h2>
<!-- padding property used here -->
<p class="geek">
This paragraph has a padding-top: 100px;
</p>
</body>
</html>
<!--Driver Code Ends-->
Example: Here, we are using the padding-top: percentage (%) property.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>
padding-top Property
</title>
<!--Driver Code Ends-->
<style>
.geek {
padding-top: 10%;
width: 50%;
font-size: 18px;
border: 1px solid black;
}
</style>
<!--Driver Code Starts-->
</head>
<body>
<h2>
padding-top Property
</h2>
<!-- padding property used here -->
<p class="geek">
This paragraph has a padding-top: 10%;
</p>
</body>
</html>
<!--Driver Code Ends-->
Example: Here, we use padding-top: initial; property.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>
padding-top Property
</title>
<!--Driver Code Ends-->
<style>
.geek {
padding-top: initial;
width: 50%;
font-size: 18px;
border: 1px solid black;
}
</style>
<!--Driver Code Starts-->
</head>
<body>
<h2>
padding-top Property
</h2>
<!-- padding property used here -->
<p class="geek">
This paragraph has a padding-top: initial;
</p>
</body>
</html>
<!--Driver Code Ends-->