Masonry
Packs variable-height children into columns with CSS columns, Pinterest-style.
<arc-masonry>Overview
Masonry packs children of different heights into columns. It uses CSS column-count and column-gap, so the browser does the layout and no script measures or positions items. Children fill the first column top to bottom, then the next, and the browser picks the break points so the columns end at similar heights.
columns sets the column count (3 by default), and gap picks the sm, md or lg spacing token. Use it for image galleries, blog post cards, or any feed where uniform row heights would waste space.
Guidelines
Do
- Set `columns` for the expected width: 2 for narrow containers, 3 or 4 for wide ones
- Combine with ResponsiveSwitcher to drop columns on smaller screens
- Use `gap="md"` for most card layouts and `gap="sm"` for dense image grids
Don't
- Don't use it for items of the same height. Use a CSS grid or AspectGrid
- Don't set more than five columns. They get too narrow to read
- Don't use it where items must read left to right. Order runs down each column, and where a column breaks depends on item heights
Features
- Children get `break-inside: avoid`, so no item is split across two columns
- The `gap` also sets the space below each child, so rows and columns are spaced alike
Preview
Usage
<arc-masonry columns="3" gap="md">
<arc-card>Short content</arc-card>
<arc-card>Taller content with more text that wraps to multiple lines</arc-card>
<arc-card>Medium content</arc-card>
<arc-card>Another short card</arc-card>
<arc-card>Variable height content for masonry layout</arc-card>
<arc-card>Brief</arc-card>
</arc-masonry>import { Masonry, Card } from '@arclux/arc-ui-react';
function ImageGallery() {
return (
<Masonry columns={3} gap="md">
<Card>Short content</Card>
<Card>Taller content with more text</Card>
<Card>Medium content</Card>
<Card>Another short card</Card>
</Masonry>
);
}<script setup>
import { Masonry, Card } from '@arclux/arc-ui-vue';
</script>
<template>
<Masonry :columns="3" gap="md">
<Card>Short content</Card>
<Card>Taller content with more text</Card>
<Card>Medium content</Card>
<Card>Another short card</Card>
</Masonry>
</template><script>
import { Masonry, Card } from '@arclux/arc-ui-svelte';
</script>
<Masonry columns={3} gap="md">
<Card>Short content</Card>
<Card>Taller content with more text</Card>
<Card>Medium content</Card>
<Card>Another short card</Card>
</Masonry>import { Component } from '@angular/core';
import { Masonry, Card } from '@arclux/arc-ui-angular';
@Component({
imports: [Masonry, Card],
template: `
<arc-masonry [columns]="3" gap="md">
<arc-card>Short content</arc-card>
<arc-card>Taller content with more text</arc-card>
<arc-card>Medium content</arc-card>
<arc-card>Another short card</arc-card>
</arc-masonry>
`,
})
export class GalleryComponent {}import { Masonry, Card } from '@arclux/arc-ui-solid';
function ImageGallery() {
return (
<Masonry columns={3} gap="md">
<Card>Short content</Card>
<Card>Taller content with more text</Card>
<Card>Medium content</Card>
<Card>Another short card</Card>
</Masonry>
);
}import { Masonry, Card } from '@arclux/arc-ui-preact';
function ImageGallery() {
return (
<Masonry columns={3} gap="md">
<Card>Short content</Card>
<Card>Taller content with more text</Card>
<Card>Medium content</Card>
<Card>Another short card</Card>
</Masonry>
);
}<!-- Auto-generated by @arclux/prism — do not edit manually -->
<!-- arc-masonry — requires masonry.css + base.css (or arc-ui.css) -->
<div class="arc-masonry">
<div class="masonry">
Masonry
</div>
</div><!-- Auto-generated by @arclux/prism — do not edit manually -->
<!-- arc-masonry — self-contained, no external CSS needed -->
<div class="arc-masonry" style="display: block">
<div style="column-count: 3; column-gap: 16px">
Masonry
</div>
</div>API
columnsnumber3- Number of columns in the masonry grid. The browser distributes children across columns to minimize overall height difference.
gap'sm' | 'md' | 'lg''md'- Spacing between columns and rows, mapped to design system spacing tokens (--space-sm, --space-md, --space-lg).
See also
- Aspect GridEqual columns where every child has the same aspect ratio.
- Dashboard GridWraps dashboard cards into as many columns as fit, with no breakpoints to write.
- CardContent container with a border and hover effects. When it links somewhere, the whole surface is the link and the border turns to a gradient on hover.