spacing

padding

Shorthand for inner spacing between an element's content and its border. Padding never collapses and adds to an element's rendered footprint unless box-sizing: border-box is set.

padding: <top> <right> <bottom> <left> | <top> <horizontal> <bottom> | <vertical> <horizontal> | <all>

Common values

Value Effect
0 Removes all inside spacing
1rem Equal 1rem padding on all sides
.5rem 1rem Typical button padding
1rem 2rem Larger horizontal than vertical padding
clamp(1rem, 4vw, 4rem) Fluid responsive padding

Examples

.btn { padding: .5rem 1rem; }

Standard button padding

.section { padding: 4rem 1rem; }

Vertical rhythm for full-width sections

.card { padding: 1.5rem; box-sizing: border-box; }

Predictable card width with padding included

Gotcha

Percentage padding is calculated from the parent's width (even for top/bottom), a fact used for aspect-ratio hacks before aspect-ratio existed.

Related properties

← All CSS properties · CSS selectors · Grid vs Flexbox