CHAPTER 10
CSS Padding
CSS padding controls the space between an element's content and its border.
01. What is CSS Padding?
Padding creates inside spacing.
Padding can be applied to all four sides.
Individual padding properties can control each side.
Padding is commonly used to make buttons and cards more comfortable to read.
02. Syntax
.box {
padding: 20px;
}
.card {
padding:
20px 30px;
}
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
.card {
width: 320px;
padding:
30px;
margin:
40px auto;
background:
#ffffff;
border:
2px solid #2563eb;
border-radius:
18px;
box-shadow:
0 15px 35px
rgba(0,0,0,0.10);
}
body {
background:
#f4f7fb;
font-family:
Arial,
sans-serif;
}
</style>
</head>
<body>
<div class="card">
<h2>
CSS Padding
</h2>
<p>
Padding creates space
inside the card.
</p>
</div>
</body>
</html>
04. Important Points
✓
Padding creates space inside the border.
✓
Padding improves readability and visual spacing.
✓
Padding contributes to the element's size unless box-sizing: border-box is used.
05. Common Mistakes
⚠
Confusing padding with margin.
⚠
Using excessive padding that makes a component unnecessarily large.
06. Real World Use
Padding is essential for cards, buttons, navigation links, forms and content sections.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Create a Comfortable Card
Create a card with heading and paragraph and use padding to create comfortable space inside it.