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>