Search⌘ K
AI Features

Margins

Explore the CSS margin property to create space around elements in the box model. Learn to specify margins individually or with shorthand, use units like px and em, and apply auto for horizontal centering. This lesson helps you master essential spacing techniques for layout design.

Box model properties

The values held by the margin, padding, and border properties directly affect the size of an element’s box. We’ll see how these properties relate to the box model, beginning with the margin property.

The margin property

The margin property defines the outer portion of the box model. It creates space around an element outside ofany borders. In other words, it’s an invisible space around the box that pushes other elements away from it.

We can specify our element’s margins on each side, like so:

 ...