HTML CSS JavaScript SEO Python Posts Privacy About Contact

CSS Padding

The CSS padding properties are used to generate space around an element's content, inside of any defined borders.

Padding is the transparent space inside an element’s border — between the border and the actual content. More padding = more breathing room for your content.

Try It — Padding in Action

Preview

Padding Shorthand

ShorthandSets
padding: 20pxAll 4 sides = 20px
padding: 10px 30pxTop & Bottom = 10px, Left & Right = 30px
padding: 10px 20px 30px 40pxTop, Right, Bottom, Left (clockwise)

Padding vs Margin

PaddingMargin
LocationInside the borderOutside the border
BackgroundShows element’s backgroundAlways transparent
CollapseDoes not collapseAdjacent margins collapse

Tip: When you need space inside a button or card, use padding. When you need space between two elements, use margin.