๐Ÿ”
๐Ÿ‘ถ Kids๐Ÿ“ Blog About Contact ๐Ÿš€ Get Started Free

CSS Margins

The CSS margin properties are used to create space around elements, outside of any defined borders.

Margin is the transparent space outside an elementโ€™s border โ€” it pushes other elements away. You can set margins for all four sides individually or using shorthand.

Try It โ€” Margins in Action

Preview

Margin Shorthand Values

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

Tip: margin: 0 auto is the classic way to horizontally center a block element. The element must have a defined width for this to work.