The spacing around and between elements is just as important and, again, there are many options.

What Is gap?

CSSgapis a simple yet essential style property to help define the spacing of your design layouts.

A pair of feet seen from above, near the edge of a station platform with “Mind The Gap” written on the floor

DanielGonzalezPhoto /Shutterstock

You should usegapwith container elements that define the layout, rather than elements within the container.

The property aims to create uniform space between items rather than more complex, variable spacing.

The flex-direction your layout uses will determine whether the row gap or column gap applies.

A Flex layout showing three elements alongside each other.

Think of gap as a minimum value unless you are explicitly controlling all other properties that can affect spacing.

When using two values for gap, check that you have them the right way round.

The exact way youll use gap will vary depending on which layout scheme youre applying it to.

A Flex layout showing three elements alongside each other with gaps in between.

A Flex layout showing three elements across two rows with horizontal and vertical gaps.

A Grid layout showing nine elements with margins around them.

A Grid layout showing nine elements with margins around them and large gaps between them.

A three-column layout showing a paragraph of sample text.

A three-column layout showing justified text with very small gaps between columns.

A three-column layout showing justified text with gaps between columns.