What is Padding?
Padding is the space inside an element, between its content and border. It controls internal spacing.
Basic Padding
CSSRead-only
1
Individual Sides
CSSRead-only
1
Shorthand Property
CSSRead-only
1
Shorthand Variations
| Values | Meaning |
|---|---|
| 1 value | All sides |
| 2 values | Top/Bottom, Left/Right |
| 3 values | Top, Left/Right, Bottom |
| 4 values | Top, Right, Bottom, Left |
Padding and Box Model
Padding increases the total size of an element unless box-sizing: border-box is used.
CSSRead-only
1
Padding Example
CSSRead-only
1
Difference: Padding vs Margin
| Property | Description |
|---|---|
| Padding | Space inside element |
| Margin | Space outside element |
Best Practices
- Use padding for internal spacing
- Use shorthand for clean code
- Use box-sizing to control layout size
- Maintain consistent spacing across UI
Common Mistakes
- Confusing padding with margin
- Breaking layout due to extra padding
- Not using box-sizing
- Inconsistent spacing values
Conclusion
CSS padding controls spacing inside elements and is essential for layout, readability, and UI design.