Padding
padding adds space between the content and the border. It follows the same shorthand as margin: one to four values. The background colour shows through the padding.
Padding cannot be negative or auto. Use padding rather than margin when you want the clickable or coloured area of an element to grow, such as on buttons.
Example
<style>
.tight { background: #fecaca; padding: 2px; }
.roomy { background: #bbf7d0; padding: 20px 40px; }
button { padding: 12px 28px; border: 0; background: #1d4ed8; color: white; border-radius: 6px; }
</style>
<p class="tight">Tight padding</p>
<p class="roomy">20px top and bottom, 40px left and right</p>
<button>Roomy button</button>Exercise
Give the button 10px vertical and 20px horizontal padding.
button { padding: ; }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.