Masonry
Cards of different heights in columns, like a pinboard; one column on narrow screens.
Example
Short note.
A longer card with more text, so it takes more space than its neighbors in the column.
Medium card with a little more text.
Another short one.
The last card, of medium length, closes the set.
<focsd-masonry min-column-width="12rem"> <focsd-card><p>Short note.</p></focsd-card> <focsd-card ><p> A longer card with more text, so it takes more space than its neighbors in the column. </p></focsd-card > <focsd-card><p>Medium card with a little more text.</p></focsd-card> <focsd-card><p>Another short one.</p></focsd-card> <focsd-card><p>The last card, of medium length, closes the set.</p></focsd-card></focsd-masonry>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-masonry.js';</script>
<focsd-masonry min-column-width="12rem">…</focsd-masonry>import { Masonry } from '@focsd-dev/react';
export function Example() { return <Masonry min-column-width="12rem">…</Masonry>;}<script setup>import '@focsd-dev/components/focsd-masonry.js';</script>
<template> <focsd-masonry min-column-width="12rem">…</focsd-masonry></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-masonry.js';
// template<focsd-masonry min-column-width="12rem">…</focsd-masonry><script> import '@focsd-dev/components/focsd-masonry.js';</script>
<focsd-masonry min-column-width="12rem">…</focsd-masonry>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
columns | columns | number | 0 |
min-column-width | minColumnWidth | string | 16rem |
gap | gap | number | 4 |
order | order | 'dom' | 'balanced' | dom |
Slots
| Slot | Description |
|---|---|
(default) | The items. |
CSS parts
Style the inside of the component with ::part(), for example focsd-masonry::part(probe).
| Part | Description |
|---|---|
probe | A hidden element used to measure the minimum column width. |
Accessibility
- Uses CSS masonry (
display: grid-lanes) where the browser has it, and places items itself elsewhere. - The default
order="dom"keeps the visual order close to the reading and focus order (WCAG 1.3.2, 2.4.3). - Where the browser has CSS masonry, it places each item in the shortest column itself, so
orderhas no effect and the layout behaves likeorder="balanced". If the visual order must follow the reading order everywhere, setnativeMasonry = false. order="balanced"packs tighter but can separate what is next to what visually from the focus order: use it only for items that do not need to be read in sequence.- Children keep their own semantics; the container adds no role.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.