Layouts Overview
How Vanilla Breeze arranges things on a page: a small set of layouts that each do one job, respond to the space they are given and nest inside each other.
The approach
Each layout does one job. A stack puts things in a column with even gaps. A grid makes as many equal columns as fit. A sidebar puts a narrow column beside a wide one. You build a page by nesting them: a grid of cards inside a stack inside a sidebar.
The layouts are CSS only. They need no script and no breakpoints of your own: most of them wrap or stack when their own space runs out, so the same markup works in a full-width page and in a narrow column.
Every layout can be written two ways. As an element, <layout-stack>, when you need a wrapper. As an attribute, data-layout="stack", on an element you already have. Both use the same rules and take the same modifiers.
<layout-stack data-layout-gap="l"> <h2>Opening hours</h2> <p>Monday to Saturday, 09:00 to 18:00.</p></layout-stack> <section data-layout="stack" data-layout-gap="l"> <h2>Opening hours</h2> <p>Monday to Saturday, 09:00 to 18:00.</p></section>
Which layout to use
Start from what you need the children to do. The demo applies four of these to one list: only the data-layout value changes.
| You need |
Use |
Attribute form |
| Children one above the other, evenly spaced |
<layout-stack> |
data-layout="stack" |
| Items in a row that wrap to the next line: buttons, tags, a toolbar |
<layout-cluster> |
data-layout="cluster" |
| Equal columns, as many as fit: cards, products, stats |
<layout-grid> |
data-layout="grid" |
| A few items that share one row, or all stack when the row gets too narrow |
<layout-switcher> |
data-layout="switcher" |
| A narrow column beside a wide one, inside a component or a content area |
<layout-sidebar> |
data-layout="sidebar" |
| Two columns in a fixed ratio |
Attribute only |
data-layout="split" |
| A row that scrolls sideways and never wraps |
<layout-reel> |
data-layout="reel" |
| A column with a maximum width, centered in its parent |
<layout-center> |
data-layout="center" |
| Running text at a readable line length |
<layout-text> |
data-layout="prose" |
| Text that flows across newspaper columns |
<layout-columns> |
data-layout="columns" |
| A tall area with one thing centered in it: a hero, a sign-in screen, an error page |
<layout-cover> |
data-layout="cover" |
| A picture beside its text: an avatar and a comment |
Attribute only |
data-layout="media" |
| A header, a body and a footer inside one component |
Attribute only |
data-layout="regions" |
| Something placed over its container: a badge on a corner, a label on an image |
<layout-imposter> |
Element only |
| The whole page: header, navigation, main, footer |
Attribute only |
data-page-layout on <body> |
Three more elements share the layout- prefix but give a surface and not an arrangement: <layout-card> (a padded box with a background), <layout-canvas> (a raised sheet for page content) and <layout-badge> (a small status chip). Put them inside the layouts above.
Close calls
- Grid or switcher. A grid drops one column at a time as it narrows, so three cards become two and one. A switcher never does that: its children are all in one row or all stacked. Use a switcher for a small, fixed number of things that belong together.
- Grid or cluster. Grid children are all the same width. Cluster children keep the width of their content.
- Cluster or reel. A cluster wraps onto a new line. A reel stays on one line and scrolls.
- Sidebar or page layout.
data-page-layout places the page regions (header, nav, main, aside, footer) and goes on <body>. <layout-sidebar> is for two columns anywhere below that.
- Center or text. Center caps the width of a block of mixed content and centers it. Text caps the width in characters for reading and spaces headings and paragraphs. Content width compares them.
- Imposter or dialog. An imposter only positions. It does not trap focus or close on Escape. For anything a reader interacts with as a modal, use
<dialog>.
What is handled and what you provide
| Area |
The library handles |
You provide |
| Narrow screens |
Wrapping, stacking and column counts, decided by the width of each layout or its container |
The viewport meta tag, and a check that the stacked order reads well |
| Spacing |
One scale of nine sizes, a default gap for every layout, density presets for a whole region |
The gap size where the default is not what you want |
| Line length |
Width caps for content and for running text, and a way for one child to break out |
The choice of which cap suits the page |
| Page structure |
Eight page templates that place <header>, <nav>, <main>, <aside> and <footer> by element type |
Those elements, as direct children of <body>, in reading order |
| Direction |
Every layout follows dir: a sidebar on the start side is on the right in a right-to-left page |
dir on the page |
| Semantics |
Nothing. A layout changes position only |
The right elements, a source order that matches the reading order, and names for landmarks |
Modifiers
A layout is adjusted with data-layout-* attributes on the same element. The names are shared: data-layout-gap means the same thing on a stack, a grid and a sidebar.
<ul data-layout="grid" data-layout-min="l" data-layout-gap="xl"> <li>...</li></ul>
| Modifier |
Sets |
Read by |
data-layout-gap | Space between children, none or 3xs to 3xl | Stack, cluster, grid, switcher, sidebar, reel, cover, center, split, media, regions and the page layouts |
data-layout-align | Alignment across the layout's direction | Stack, cluster, reel, split, media |
data-layout-justify | Distribution along the row | Cluster |
data-layout-min | Smallest column width (grid), or smallest height (cover) | Grid, cover |
data-layout-max | Largest width | Center, prose |
data-layout-nowrap | Stops the layout wrapping or stacking | Cluster, sidebar, split, page layouts |
A modifier applies only to the element it is on. A grid nested in a grid with data-layout-gap="3xl" still gets the default gap. The data-layout reference lists every modifier and value.
Page, content area, component
Layout happens at three levels, and each has its own tool.
<body data-page-layout="sidebar-left"> <header>Harbour Books</header> <nav aria-label="Primary">...</nav> <main data-layout="stack" data-layout-gap="xl"> <h1>New this week</h1> <ul data-layout="grid" data-layout-min="m"> <li>...</li> </ul> </main> <footer>...</footer></body>
Grid Identity explains the page templates and how elements find their place in them. For a header, sidebar or footer that stays in view while the page scrolls, see data-sticky. Phone-specific concerns (safe areas, the app shell, bottom sheets) are in Mobile.
In this section
Semantic Layouts
The attribute form: layouts on the elements you already have, and what differs from the element form.
Grid Identity
Page templates that place header, nav, main, aside and footer by element type.
Responsive Behavior
How each layout wraps or stacks, which ones follow the container and which follow the viewport.
Spacing and Density
The size scale, gaps and padding, and tighter or looser spacing for a region.
Content Width
Width caps, reading measure, text columns and children that break out.
Fluid Scaling
Type and spacing that grow with the viewport, switched on with one attribute.