agyanadda@gmail.com

CSS Padding

CSS Box Model 1 min read Updated Dec 1, 2026 Topic 15 of 39

Padding is the space between an element's content and its border. The background colour fills the padding area.

Individual sides

padding-top, padding-right, padding-bottom, padding-left

Shorthand

Works like margin, clockwise from top: padding: 10px 20px 10px 20px;

Padding vs margin

Padding Margin
inside the border outside the border
shows the background always transparent
cannot be negative can be negative

Example

Example — Padding makes buttons comfortable HTML
<style>
  .btn { background: #1f386b; color: white; border: none; border-radius: 6px; }
  .small { padding: 4px 8px; }
  .large { padding: 14px 28px; font-size: 18px; }
</style>

<button class="btn small">Small padding</button>
<button class="btn large">Large padding</button>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which area shows the element's background colour?

Exercise 2 True / False

Padding can be negative.

Exercise 3 Fill in the Blank

padding: 5px 10px; gives ___px on the left side.

Frequently Asked Questions

Yes, with the default content-box. With box-sizing: border-box, padding is included inside the width.