The short version
A masonry layout needs no JavaScript in Tailwind: put the items in a container with columns-* classes, like columns-1 sm:columns-2 lg:columns-3, and the browser stacks them into columns.
Give every item break-inside-avoid, or the browser can cut a card in half and continue it at the top of the next column.
The gap class only spaces the columns. Add a bottom margin such as mb-4 to every item for the space between cards in a column.
CSS columns fill the first column before starting the next, so items 1, 2 and 3 sit under each other. Use grid-lanes or JavaScript when the order should go across.
display: grid-lanes is native CSS masonry that puts each item in the shortest column. As of October 2026 only Safari 26.4 and later ship it, so keep CSS columns as the fallback.
To build a masonry layout with Tailwind CSS, put your items in a container with a columns-* class and give every item break-inside-avoid and a bottom margin.β¦