For working professionals
For fresh graduates
More
Talk to our experts. We are available 7 days a week, 10 AM to 7 PM
Indian Nationals
Foreign Nationals
The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not .
Recommended Programs
1. Introduction
6. PyTorch
9. AI Tutorial
10. Airflow Tutorial
11. Android Studio
12. Android Tutorial
13. Animation CSS
16. Apex Tutorial
17. App Tutorial
18. Appium Tutorial
21. Armstrong Number
22. ASP Full Form
23. AutoCAD Tutorial
27. Belady's Anomaly
30. Bipartite Graph
35. Button CSS
39. Cobol Tutorial
46. CSS Border
47. CSS Colors
48. CSS Flexbox
49. CSS Float
51. CSS Full Form
52. CSS Gradient
53. CSS Margin
54. CSS nth Child
55. CSS Syntax
56. CSS Tables
57. CSS Tricks
58. CSS Variables
61. Dart Tutorial
63. DCL
65. DES Algorithm
83. Dot Net Tutorial
86. ES6 Tutorial
91. Flutter Basics
92. Flutter Tutorial
95. Golang Tutorial
96. Graphql Tutorial
100. Hive Tutorial
103. Install Bootstrap
107. Install SASS
109. IPv 4 address
110. JCL Programming
111. JQ Tutorial
112. JSON Tutorial
113. JSP Tutorial
114. Junit Tutorial
115. Kadanes Algorithm
116. Kafka Tutorial
117. Knapsack Problem
118. Kth Smallest Element
119. Laravel Tutorial
122. Linear Gradient CSS
129. Memory Hierarchy
133. Mockito tutorial
134. Modem vs Router
135. Mulesoft Tutorial
136. Network Devices
138. Next JS Tutorial
139. Nginx Tutorial
141. Octal to Decimal
142. OLAP Operations
143. Opacity CSS
144. OSI Model
145. CSS Overflow
146. Padding in CSS
148. Perl scripting
149. Phases of Compiler
150. Placeholder CSS
153. Powershell Tutorial
158. Pyspark Tutorial
161. Quality of Service
162. R Language Tutorial
164. RabbitMQ Tutorial
165. Redis Tutorial
166. Redux in React
167. Regex Tutorial
170. Routing Protocols
171. Ruby On Rails
172. Ruby tutorial
173. Scala Tutorial
175. Shadow CSS
178. Snowflake Tutorial
179. Socket Programming
180. Solidity Tutorial
181. SonarQube in Java
182. Spark Tutorial
189. TCP 3 Way Handshake
190. TensorFlow Tutorial
191. Threaded Binary Tree
196. Types of Queue
197. TypeScript Tutorial
198. UDP Protocol
202. Verilog Tutorial
204. Void Pointer
205. Vue JS Tutorial
206. Weak Entity Set
207. What is Bandwidth?
208. What is Big Data
209. Checksum
211. What is Ethernet
214. What is ROM?
216. WPF Tutorial
217. Wireshark Tutorial
218. XML Tutorial
Padding in CSS is a property that defines the space between an element’s content and its border. It is an essential part of web design because it controls how text, images, and other elements are displayed within their containers. By adjusting padding, developers can create clean layouts, improve readability, and ensure better visual balance on a webpage.
This tutorial covers everything you need to know about padding in CSS. We will explain what padding is, how it works, and the different properties you can use. You will also see practical examples with code to understand how padding affects elements in real projects. By the end, you will be confident in applying CSS padding effectively in your designs.
Step into the next chapter of your tech journey. Our Software Engineering Courses prepare you to excel beyond coding and capture high-impact opportunities.
Padding in CSS is the space between an element’s content and its border. It does not include margins or borders but only affects the area inside the element. By controlling padding, you can adjust the spacing around content, improve readability, and maintain a clean layout. Proper use of padding also influences the overall dimensions of an element, helping designers create visually balanced and well-structured web pages
Want to fast-track your tech career? Our Software Engineering Courses equip you with the skills to innovate, lead, and seize the next big opportunity.
Padding's primary use in CSS is to create space around an element's content, enhancing the visual separation between the content and its border. This extra space effectively breaks the monotony, making the design more readable and visually pleasing, thus improving the overall user experience.
The padding of an element is the space between the content and its border. This property can contain from one to four values:
Property | Description |
padding-left | Used to set the left padding of a specific element. |
padding-right | Used to set the right padding of a specific element. |
padding-top | Used to set the top padding of a specific element. |
padding-bottom | Used to set the bottom padding of a specific element. |
Here is an example:
Code:
<!--top padding is 10px
right padding is 5px
bottom padding is 15px
left padding is 20px-->
<!DOCTYPE html>
<html>
<head>
<style>
p.upGradpadding {
border: 1px solid red;
padding:10px 5px 15px 20px;
}
</style>
</head>
<body>
<h1>The padding-top,The padding-right,The padding-bottom,The padding-left Property</h1>
<p class="upGradpadding">A paragraph with a 10px top,5px right,15px bottom and 20px left padding</p>
</body>
</html>
Explanation:
The CSS style defines a class selector p.upGradpadding, which targets <p> (paragraph) elements with the class name upGradpadding. Inside the p.upGradpadding CSS block, the following properties are defined:
The paragraph element with the class upGradpadding is defined as follows: <p class="upGradpadding">A paragraph with a 10px top, 5px right, 15px bottom, and 20px left padding</p>
Visually, the paragraph will be displayed with padding as follows:
As a result, the content of the paragraph will be pushed away from each side of the paragraph by the specified padding values, and a red border will surround the entire paragraph.
Must Read: CSS Tutorial: Learn CSS from Scratch
Note: Negative values are not allowed.
Code:
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
padding: 25px 20% 3em 30px;
background-color: lightblue;
}
</style>
</head>
<body>
<h2>The padding property - 4 values</h2>
<div>This div element has a top padding of 25px, a right padding of 20%, a bottom padding of 3em,and a left padding of 30px.</div>
</body>
</html>
Explanation:
The CSS style applies to all <div> elements on the page. Inside the <style> block, the following properties are defined for the <div> element:
The content of the <div> element is "This div element has a top padding of 25px, a right padding of 20%, a bottom padding of 3em, and a left padding of 30px."
Visually, the <div> element will be displayed as follows:
Additionally, the <div> element will have a light blue background color due to the background-color: lightblue; property.
Also Read: CSS Frameworks Tutorial
Code:
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
background-color: pink;
padding-top: 50px;
padding-right: 100px;
padding-bottom: 35px;
padding-left: 80px;
}
</style>
</head>
<body>
<h2>Using individual padding properties</h2>
<div>This div element has a top padding of 50px, a right padding of 100px,
a bottom padding of 35px,and a left padding of 80px.</div>
</body>
</html>
Explanation:
The CSS style applies to all <div> elements on the page.
Inside the <style> block, the following properties are defined for the <div> element:
The content of the <div> element is "This div element has a top padding of 50px, a right padding of 100px, a bottom padding of 35px, and a left padding of 80px."
Visually, the <div> element will be displayed as follows:
Additionally, the <div> element will have a pink background color due to the background-color: pink; property. The black border, as specified by border: 1px solid black;, will surround the entire <div> element, making the padding visually distinguishable from the background.
Must Read: CSS Colors Tutorial
Code:
<!DOCTYPE html>
<html>
<head>
<style>
div.ex1 {
width: 300px;
background-color: green;
}
div.ex2 {
width: 300px;
padding: 25px;
box-sizing: border-box;
background-color: yellow;
}
</style>
</head>
<body>
<h2>Padding and element width - with box-sizing in upGradTutorial</h2>
<div class="ex1">This div is 300px wide.</div>
<br>
<div class="ex2">The width of this div remains at 300px, in spite of the 50px of total left and right padding, because of the box-sizing: border-box property.
</div>
</body>
</html>
Employing CSS padding offers numerous advantages.
Mastering padding in CSS is crucial for creating well-structured and visually appealing web pages. Padding controls the space between an element’s content and its border, directly impacting layout, readability, and overall design clarity. Proper use of padding ensures that content is not cramped and provides a clean, organized appearance. It also plays a key role in making designs responsive across different screen sizes.
By understanding CSS padding properties and values, you can efficiently manage element spacing, enhance user experience, and maintain consistency throughout your web layouts. Padding is a fundamental tool for effective web design.
Padding refers to the space between an element's content and its border, while margin in CSS is the space outside the border. Both can impact the overall layout and design of a webpage. How does CSS padding shorthand work?
CSS padding shorthand allows you to set padding for all four sides of an element in a single line of code. The order is top, right, bottom, and left. Can padding be applied to HTML elements?
Yes, padding can be applied to HTML elements using CSS to control the spacing around the content of these elements. How is padding-top and html padding-left in CSS different from each other?
padding-top applies padding to the top side of an element, while html padding-left applies padding to the left side. They help in controlling the spacing around the content in different directions.
FREE COURSES
Start Learning For Free

Author|907 articles published