Interview Question

Difference between margin and padding?

Padding is inner spacing; margin is outer spacing.

💡 Concept ✅ Quick Revision 🎨 CSS

Answer

Margin and padding create space on different sides of the border. • Padding is inside the border and receives the element background. • Margin is outside the border and remains transparent. • Margins may collapse in block layout; padding does not.

💡 Simple Example

.panel { margin: 2rem; padding: 1rem; border: 1px solid; }

⚡ Quick Revision

Padding is inner spacing; margin is outer spacing.