Build a Masonry Layout with Pure CSS column-width

Masonry-style image grid built with CSS column-width showing responsive multi-column layout.

You only need a few CSS lines to build a Masonry layout.

Here’s how it works: The magic happens with the column-width property.

.columns {
	width: 100%;
	column-width: 200px;
	gap: 1em;
}

This tells the browser: “Fit as many 200px-wide columns as you can into this container.”

If the screen is wider, more columns fit. On smaller screens, fewer columns show.

The gap sets the horizontal spacing between them.

The rest is just good styling:

  • Images set to width: 100% so they fill the column
  • object-fit: cover to keep them visually balanced
  • A bit of padding, rounded corners, and borders for aesthetics

No position hacks. No flex/grid juggling. Just native CSS doing the heavy lifting.

And it adapts instantly when you resize the container.

Link to the codepen: https://codepen.io/theosoti/pen/ogXedrz

Column-based masonry layouts are fast to implement for feeds and galleries. Always test reading flow and item ordering, because visual columns can differ from the underlying DOM sequence users navigate.

Column-based masonry is quick for feeds, but always verify reading order and keyboard navigation. Visual placement should not conflict with logical DOM sequence.

Before rollout, verify long content, dense cards, and extreme widths. Stable behavior under stress is what turns a neat trick into production CSS.

When introducing column-width, begin with one reference component and treat it as the canonical pattern. Then reuse that same pattern in similar contexts so behavior stays consistent and review time stays low.

If reading order matters, double-check keyboard and screen-reader flow so visual columns do not confuse content sequence.

You Don’t Need JavaScript ebook mockup

I wrote a guide about building modern UI with HTML and CSS first. It covers practical patterns you can use before reaching for JavaScript.

Learn more

    No strings attached, unsubscribe anytime!

    Other short articles you might like

    Explore more articles on front-end development, covering HTML, CSS and JavaScript for building high-performance websites.