Skip to content
Focsd homeFocsd homeFocsd
Forms

Masonry

Cards of different heights in columns, like a pinboard; one column on narrow screens.

  • Tag: focsd-masonry
  • Pattern: Columns of varying height, DOM-order placement by default
  • Category: Layout

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.

HTML
<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>

API

Attributes

AttributePropertyTypeDefault
columnscolumnsnumber0
min-column-widthminColumnWidthstring16rem
gapgapnumber4
orderorder'dom' | 'balanced'dom

Slots

SlotDescription
(default)The items.

CSS parts

Style the inside of the component with ::part(), for example focsd-masonry::part(probe).

PartDescription
probeA 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 order has no effect and the layout behaves like order="balanced". If the visual order must follow the reading order everywhere, set nativeMasonry = 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.