What is the difference between margin and padding in CSS?

Padding is the space inside the element, between the content and the border. Margin is the space outside the border, between this element and others.

PointPaddingMargin
PositionInside the borderOutside the border
Background colourShows in the paddingMargin is always transparent
Negative valueNot allowedAllowed
autoNoYes, to centre a block
Output in the browser
padding 20px, margin 12px

See padding and margin.


Learn more about the similar topics:
Tutorials
CSS Borders
Rounded Corners in CSS
CSS Height and Width
CSS Padding
CSS Margins
CSS Box Model
CSS Outline
Exercises & Assignments
Write CSS to create a box with border, padding and rounded corners
Write CSS to create a circle and a pill-shaped button
Write CSS to style a login form
Interview Questions & Answers
What is the CSS box model?
What is the difference between margin and padding in CSS?
What is box-sizing: border-box in CSS?