No Login Data Private Local Save

CSS Masonry Layout Experiment - Online grid‑template‑rows: masonry

8
0
0
0

CSS Masonry Layout Experiment

Explore grid-template-rows: masonry — the future of native CSS masonry

CSS Grid Level 3
Controls
26
4px40px

Drag sliders to see real‑time changes
Firefox (flag) Chrome (pending) 4 cols · 16px gap · 8 items

No cards yet

Click "Add Random Card" to start experimenting

Generated CSS

Frequently Asked Questions

CSS masonry layout is a native way to create Pinterest-style staggered grid layouts without JavaScript. The grid-template-rows: masonry property is part of the CSS Grid Level 3 specification. When applied to a grid container, it tells the browser to use a masonry algorithm: items are placed in the column with the shortest height, creating a tightly-packed, organic layout. Unlike traditional CSS Grid where rows are strictly aligned, masonry allows each item to sit directly beneath the one above it, eliminating uniform row gaps and creating a visually dynamic flow.

As of 2025, native CSS masonry is only available in Firefox behind a feature flag. To enable it, navigate to about:config and set layout.css.grid-template-masonry-value.enabled to true. Chromium-based browsers (Chrome, Edge, Brave, Opera) and Safari do not yet support this feature. The CSS Working Group is actively discussing the specification, and broader implementation is expected once the spec reaches a more stable stage. In the meantime, developers use JavaScript libraries or CSS column-based fallbacks.

CSS Columns (column-count) distribute content top-to-bottom, filling each column completely before moving to the next. This means items are ordered vertically within each column. True masonry (like grid-template-rows: masonry) places items left-to-right, always inserting into the shortest column. This preserves horizontal reading order and creates a more natural visual flow. For image galleries and card layouts where left-to-right order matters, true masonry is superior. CSS columns work well for text-heavy content where vertical reading order is acceptable.

For production sites, the most reliable approach is using a lightweight JavaScript library such as Masonry.js, Isotope, or a custom implementation with absolute positioning. You can also use CSS columns as a progressive enhancement fallback. The pattern looks like: use @supports (grid-template-rows: masonry) to detect native support and provide the native CSS; otherwise fall back to a JS-based solution or CSS columns. This ensures your layout works across all modern browsers while being ready for the future native implementation.

grid-template-rows: masonry is proposed as part of CSS Grid Level 3. It is currently in the draft stage and has been implemented experimentally in Firefox. The CSS Working Group is evaluating feedback from the experimental implementation before finalizing the specification. There is ongoing discussion about whether masonry should be part of the Grid specification or become its own separate display type (e.g., display: masonry). The final decision will shape how developers use this feature in the coming years.

Native CSS masonry offers significant performance advantages: no layout thrashing (the browser handles positioning internally), no JavaScript overhead for calculations, automatic reflow on resize without debounce handlers, and better mobile battery life since all computation happens in the browser's optimized rendering engine. JavaScript solutions must recalculate positions on every resize, content change, or image load, which can cause jank. Native masonry also benefits from GPU-accelerated rendering and integrates seamlessly with other CSS features like animations and transitions.

In the current draft specification, when grid-template-rows: masonry is applied, some traditional grid features behave differently. Spanning items across multiple columns still works with grid-column: span 2. However, explicit row placement (grid-row) is ignored because the masonry algorithm determines row positions automatically. Named grid lines for columns remain functional, but row-based naming has limited use. The spec continues to evolve, so the final feature set may differ from the experimental Firefox implementation.