How to Add Padding in HTML

Use CSS padding when you want to create space inside an HTML element, between its content and its border. This makes buttons, cards, containers, and text blocks easier to read and better spaced.

What you’ll build or solve

You’ll learn how to add inner spacing to HTML elements using the padding property. You’ll also know when to use one value versus separate values for different sides.

When this approach works best

This approach is the right choice when the content inside an element feels cramped and needs breathing room.

Common real-world scenarios include:

  • Adding space inside buttons
  • Creating comfortable card layouts
  • Spacing text away from container edges
  • Improving form field and input readability

This is a bad idea when you want space between elements. In that case, use margin instead.

Prerequisites

You only need:

  • A basic HTML file
  • A text editor
  • Basic HTML and CSS knowledge

Step-by-step instructions

Step 1: Add the padding property to the element

Apply padding in CSS to create space inside the element.

<div class="card">Learn HTML faster</div>

<style>
  .card {
    padding: 20px;
  }
</style>

For different spacing on specific sides, use multiple values in the same property.

<div class="card">Learn HTML faster</div>

<style>
  .card {
    padding: 16px 24px;
  }
</style>

What to look for:

  • One value adds the same padding on all four sides
  • Two values mean top/bottom, then left/right
  • Four values follow top, right, bottom, left
  • Use padding for buttons, cards, forms, and text containers
  • Do not use padding when the real goal is spacing between separate elements

Examples you can copy

Button padding

<button class="cta">Start Learning</button>

<style>
  .cta {
    padding: 12px 24px;
  }
</style>

Card spacing

<div class="card">
  <h2>Frontend Course</h2>
  <p>Master HTML, CSS, and JavaScript.</p>
</div>

<style>
  .card {
    padding: 24px;
  }
</style>

Form input spacing

<input class="email-input" type="email" placeholder="Your email">

<style>
  .email-input {
    padding: 10px;
  }
</style>

Common mistakes and how to fix them

Mistake 1: Using margin instead of padding

What the reader might do:

<div class="card">Learn HTML</div>

<style>
  .card {
    margin: 20px;
  }
</style>

Why it breaks: margin adds space outside the element, so the content inside still feels tight.

Corrected approach:

<div class="card">Learn HTML</div>

<style>
  .card {
    padding: 20px;
  }
</style>

Mistake 2: Adding too much padding

What the reader might do:

<button style="padding: 80px;">Click me</button>

Why it breaks: too much inner spacing can make the element oversized and awkward, especially on mobile screens.

Corrected approach:

<button style="padding: 12px 24px;">Click me</button>

Mistake 3: Forgetting how multiple values work

What the reader might do:

<div style="padding: 10px 20px 30px;">
  Mixed spacing
</div>

Why it breaks: three values do not map evenly to all sides the way many beginners expect.

Corrected approach:

<div style="padding: 10px 20px 30px 40px;">
  Controlled spacing
</div>

This follows top, right, bottom, left.

Troubleshooting

If the content still touches the border, check that the CSS selector matches the correct class or element.

If the element becomes too large, reduce the padding values.

If the spacing appears outside the element, switch from margin to padding.

If one side looks uneven, use four values to control each side directly.

Quick recap

  • Use padding to create space inside an HTML element
  • One value applies to all sides
  • Two or four values give more side control
  • Use it for buttons, cards, forms, and text blocks
  • Use margin instead when spacing between elements is the goal