Overview
A cluster lays its children out in a row and wraps them onto new lines when they run out of room, with an even gap in both directions. It is a wrapping flex row (display: flex; flex-wrap: wrap) whose items keep their own content width.
By default the gap is s, items are vertically centred (align-items: center) and packed at the start of the line. Because items are content-sized, direct main, article, section and aside children drop their query-container status, which would otherwise collapse them to zero width; data-container opts one back in.
Element and attribute forms
Any element can be a cluster with data-layout="cluster". The same data-layout-* modifiers work on both forms; the two below lay out identically. The attribute form on a <ul> also tells screen readers how many items there are.
1234567891011
<layout-cluster data-layout-gap="xs"> <layout-badge>HTML</layout-badge> <layout-badge>CSS</layout-badge> <layout-badge>JavaScript</layout-badge></layout-cluster> <ul class="unstyled" data-layout="cluster" data-layout-gap="xs"> <li><layout-badge>HTML</layout-badge></li> <li><layout-badge>CSS</layout-badge></li> <li><layout-badge>JavaScript</layout-badge></li></ul>
Which to choose: use the attribute form when a semantic element already wraps the items: a <nav>, <ul>, <footer> or <menu>. Use <layout-cluster> when there is no meaningful element to carry it and you would otherwise add a wrapper. In the attribute form, main, article, section and aside are also container-query containers, which the element is not, so container queries inside the cluster resolve against it. See data-layout for the full comparison and Semantic Layouts for the approach.
Examples
Gap
The data-layout-gap attribute controls spacing between items.
12345
<layout-cluster data-layout-gap="xs"> <button type="button">Button</button> <button type="button">Button</button> <button type="button">Button</button></layout-cluster>
Justify
The data-layout-justify attribute controls horizontal distribution.
1234567891011
<layout-cluster data-layout-justify="start">...</layout-cluster> <layout-cluster data-layout-justify="center">...</layout-cluster> <layout-cluster data-layout-justify="end">...</layout-cluster> <layout-cluster data-layout-justify="between">...</layout-cluster>
Align
The data-layout-align attribute controls vertical alignment.
1234567891011121314
<layout-cluster data-layout-align="start">...</layout-cluster> <layout-cluster data-layout-align="center">...</layout-cluster> <layout-cluster data-layout-align="end">...</layout-cluster> <layout-cluster data-layout-align="stretch">...</layout-cluster> <layout-cluster data-layout-align="baseline">...</layout-cluster>
No wrap
data-layout-nowrap keeps every item on one line. Items no longer wrap, so in a narrow container they overflow; give the cluster (or its parent) overflow-x: auto so the overflow scrolls instead of spilling out. Use it for short toolbars and breadcrumbs that must stay on one line.
1234567
<layout-cluster class="toolbar" data-layout-gap="xs" data-layout-nowrap> <button type="button">Bold</button> <button type="button">Italic</button> <button type="button">Underline</button> <button type="button">Link</button> <button type="button">Quote</button></layout-cluster>
.toolbar { overflow-x: auto;}
Overlap
The data-layout-overlap attribute overlaps the items, for avatar groups and stacked chips. Items stay in DOM order, so what sighted users see matches reading and focus order; each later item stacks above the one before it, and a hovered or focused item is lifted to the top.
- Overlap sizes. Each item after the first is pulled back by
xs 0.25rem, s 0.5rem (the bare attribute), m 0.75rem or l 1rem.
- Gap is forced to 0. The overlap comes from negative inline margins, so
data-layout-gap has no effect.
- Surface-coloured ring. Each item gets a 2px
box-shadow ring in var(--color-surface) to separate it from its neighbour. In the list form, <user-avatar> draws the same ring itself, because the square <li> would otherwise carry it.
Mark an avatar group up as a list, as on the <user-avatar> page (Avatar Group): one <li> per person, the list named by a visible heading with aria-labelledby, and an aria-label on the +N
chip that says what it stands for.
1234567891011121314151617
<h2 id="overlap-default">Project members</h2><ul class="unstyled" data-layout="cluster" data-layout-overlap aria-labelledby="overlap-default"> <li><user-avatar><img src="jane.jpg" alt="Jane Doe" /></user-avatar></li> <li><user-avatar><img src="john.jpg" alt="John Smith" /></user-avatar></li> <li><user-avatar><img src="alex.jpg" alt="Alex Johnson" /></user-avatar></li> <li> <user-avatar role="img" aria-label="3 more members"> <span data-fallback aria-hidden="true">+3</span> </user-avatar> </li></ul> <ul class="unstyled" data-layout="cluster" data-layout-overlap="xs" aria-labelledby="overlap-xs"> <li><user-avatar data-size="sm" role="img" aria-label="Ana Lopez"><span data-fallback aria-hidden="true">AL</span></user-avatar></li> ...</ul>
On a background other than --color-surface, match the ring to it by re-declaring the token on the group. That recolours the separator on every item, including the ring that <user-avatar> draws in the list form:
.members-on-card { --color-surface: var(--color-surface-raised);}
Button group
12345
<layout-cluster data-layout-gap="s"> <button type="button">Save</button> <button type="button" class="secondary">Cancel</button> <button type="button" class="ghost">Reset</button></layout-cluster>
Tag cloud
12345
<layout-cluster data-layout-gap="xs"> <span class="tag">HTML</span> <span class="tag">CSS</span> <span class="tag">JavaScript</span></layout-cluster>
Card footer actions
1234567
<layout-cluster data-layout-gap="s" data-layout-justify="between"> <layout-cluster data-layout-gap="xs"> <button type="button">Edit</button> <button type="button">Delete</button> </layout-cluster> <button type="button">View Details</button></layout-cluster>
Navigation
123456789
<header data-layout="cluster" data-layout-gap="l" data-layout-justify="between"> <a href="/"><brand-mark>Acme</brand-mark></a> <nav aria-label="Main" data-layout="cluster" data-layout-gap="m"> <a href="#">Home</a> <a href="#">About</a> <a href="#">Services</a> <a href="#">Contact</a> </nav></header>
The navigation is a real <nav> landmark carrying the layout through data-layout="cluster" — no extra wrapper.