CSS Generators

Masonry Layout

All tools

Get a Pinterest-style stacked layout from plain CSS columns, with no script or library.

How it works

Four simple steps

1

Pick a column count

Enter a value between 2 and 6 columns.

2

Review the two rules

The container rule sets columns and the child rule prevents splits.

3

Apply the class

Add class masonry to the wrapper around your cards.

4

Copy the CSS

Copy the snippet or download masonry.css.

Masonry Layout

About Masonry Layout

A testimonials section has quotes of very different lengths, and a regular grid leaves big empty gaps under the short ones. A columns-based layout lets each card sit directly under the one above it. Pick the column count and copy the rule.

Set the number of columns (2 to 6) and the tool writes two rules. The .masonry container gets column-count and a 1rem column-gap. Its direct children get break-inside: avoid, so a card never splits across two columns, and a 1rem bottom margin to space the stacked items. Add the class to any wrapper and the children flow into the columns.

The main thing to know before you use it: CSS columns fill top to bottom, column by column. Item 1 sits at the top of the first column, item 2 under it, and the second column starts only when the first is full. For galleries and quotes that is fine, but for content where reading order matters (newest first, ranked lists) the visual order will confuse people. In that case use the CSS grid layout tool and accept even row heights. For responsive behaviour, lower column-count inside a media query, which the media query and clamp() starter helps you set up. More layout tools are in the CSS generators category.

The output updates as soon as you change the number.

Keyboard shortcut

Ctrl Enter - Run tool
FAQ

Frequently asked questions

See all FAQs

Answers for this tool. For site-wide help, open the FAQ hub.

That is how CSS multi-column layout works. Content flows down the first column, then continues at the top of the next. If order across rows matters, use grid instead.

Native masonry layout is still being specified and is not available in all stable browsers. The columns approach works everywhere today.

Make sure break-inside: avoid is on the direct children of the masonry container. If cards are wrapped in another element, move the rule to that wrapper.

View more FAQs

Related tools

View all

Tailwind Class Sorter

Sort Tailwind classes and detect conflicting utilities with a winner explanation.

Open

Design System Diff Lab

Diff design tokens and inspect CSS @layer order and selector specificity locally.

Open

SVG Path Inspector

Parse SVG path commands, preview on canvas, round and minify coordinates.

Open

Flexbox Generator

Build flex layouts visually.

Open

Explore 321 free tools

Everything you need as a developer, marketer or creator - in one beautiful place.

Browse all tools