Course contentsShow
← Web Development
Lesson 142 of 2,9823. CSS FundamentalsFree lesson

Padding: Inner Spacing

Add space inside elements between content and border using padding properties.

Padding: Inner Spacing

What you'll learn: How to add breathing room inside an element between its content and border using the padding property.

What Is Padding?

Remember the Box Model? Padding is the transparent space between an element's content and its border. It's like the cushioning inside a picture frame—it pushes the content away from the edges, making everything more comfortable to read and visually appealing.

Unlike margin (which adds space outside the border), padding expands the element's visible area from the inside.

How Padding Works

You control padding with CSS properties:

.box {
  padding: 20px; /* Equal padding on all four sides */
}

.card {
  padding-top: 10px;
  padding-right: 15px;
  padding-bottom: 10px;
  padding-left: 15px;
}

.button {
  padding: 10px 20px; /* Vertical | Horizontal */
}

.article {
  padding: 10px 20px 15px 5px; /* Top | Right | Bottom | Left (clockwise) */
}

Think of It Like This

Imagine a text message bubble in a chat app. The padding is the space between the text and the bubble's edge. Without padding, words would touch the bubble border—cramped and hard to read. With padding, the text has room to breathe.

Padding and Box Sizing

Remember box-sizing? With content-box, padding adds to your declared width. With border-box (usually preferred), padding is included in the total width.

Key Takeaway: Padding creates internal spacing that pushes content away from an element's border, improving readability and visual comfort—use shorthand notation to set all sides efficiently.