CSS padding Property Explained
What the CSS padding property does, with an example.
Published November 4, 2026
padding sets the space between an element's content and its border. It is inside the box, so the element's background extends under it.
How it works
The shorthand mirrors margin: 1–4 values. With box-sizing: border-box, padding is included in the element's width.
Padding cannot be negative or auto.
Values and effects
padding: 16px; → all sides
padding: 8px 16px; → vertical, horizontal
padding: 0 1rem 2rem; → top, sides, bottom
Practical examples
Button
.btn { padding: .5rem 1rem; }Card with box-sizing
*, *::before, *::after { box-sizing: border-box; }
.card { padding: 1.5rem; width: 100%; }Logical
.box { padding-inline: 1rem; padding-block: .5rem; }Common mistakes
- Forgetting box-sizing so padding widens elements.
- Using padding for space between items (use gap).
- Percent padding being relative to the container's width.
Key takeaways
- padding in one line: padding sets the space between an element's content and its border.
- Inspect it live in DevTools → Styles.
- Test across browsers and screen sizes.
FAQ
Can padding be percentage?
Yes, relative to the width of the containing block, even for top and bottom.
Is padding supported in all browsers?
Yes in all modern browsers; check caniuse.com for edge cases.