Write semantic HTML and let CSS place it. A header, nav, main, aside and footer take their grid areas from what they are, with no classes.
How it works
In most layout systems you tell each element where to go with a class. Here an element's place comes from what it is. Write <header>, <nav>, <main>, <aside> and <footer>, choose a template on their parent, and each element goes to the grid area that carries its name. That is the element's grid identity.
Change the template and the same markup becomes a different layout. No element needs to change.
<body data-page-layout="sidebar-left"> <header>Site header</header> <nav>Navigation</nav> <main>Content</main> <footer>Site footer</footer> </body>
Three tiers
The idea applies at three levels. Each is scoped to its own container, so they nest without clashing.
| Tier |
Set with |
Places |
| Page |
data-page-layout on <body> |
The page regions, in areas named body-header, body-nav, body-main, body-aside and body-footer |
| Main |
data-layout="sidebar-left" or "sidebar-right" on <main> |
A sidebar inside the content area, in areas named main-nav, main-article and main-aside |
| Component |
data-layout="regions" or "media" on any element |
The parts of one component, by element type: header first, footer last, a figure beside its content |
Page level
Put data-page-layout on <body>. Its direct children are placed by element type. This is the only page-template system in Vanilla Breeze. This page explains the idea; the attribute page is the full reference for modifiers, the mobile drawer and custom properties.
Try it. The demo's markup stays the same while the buttons change the template. Each region prints the grid area it was given.
Which element goes where
| Element |
Grid area |
<header> | body-header |
<nav> | body-nav |
<main> | body-main |
<aside> | body-aside |
<footer> | body-footer |
a second <nav> | body-nav-secondary (no built-in template defines it) |
<nav class="bottom"> | auto (flows in the next free cell) |
Only direct children of the data-page-layout element are placed. Other children, such as a <section> or a custom element, flow into the next free cell unless they take data-layout-area.
Templates
A template has areas for some elements and not others. Use the elements in the "Places" column.
| Template |
Shape |
Places |
stack | One column. Also what a bare data-page-layout gives. | header, nav, main, aside, footer |
sidebar-left | Navigation column, then main | header, nav, main, footer |
sidebar-right | Main, then a sidebar column | header, main, aside, footer |
holy-grail | Three columns: nav, main, aside | header, nav, main, aside, footer |
app-shell | A navigation bar the full height of the page, beside header and main | header, nav, main |
dashboard | Header across the top, nav beside main. The nav becomes a drawer on small screens. | header, nav, main |
article | One centered column for reading | header, main, footer |
landing | One column with extra named areas for marketing sections | header, nav, main, footer, plus hero, feature and cta |
An element the template has no area for is pushed into an extra track at the edge of the grid. That track has no width, so the element collapses and its content is lost from view. An <aside> under sidebar-left is the usual case. Leave such elements out, or choose a template that places them.
Each template is a custom property named --tpl-name, for example --tpl-sidebar-left. The properties are declared on the [data-page-layout] element and not on :root, so to replace a template, set the property on that element: body { --tpl-sidebar-left: …; }.
When an element is missing
A template drops a column when the element for it is absent. The styles use :has() to see which children are present.
sidebar-left without <nav>: one column.
sidebar-right without <aside>: one column.
holy-grail without <aside>: two columns, nav and main.
holy-grail without <nav>: two columns, main and aside.
holy-grail without both: one column.
So one template can serve pages that have a sidebar and pages that do not. The element must be absent from the markup: a hidden element still counts as present and keeps its column. To drop the nav column while keeping the element, set data-sidebar="hidden" on the layout.
<body data-page-layout="sidebar-left"> <header>Site header</header> <main>Full-width content</main> <footer>Footer</footer></body>
Small screens
Below 48rem, sidebar-left, sidebar-right, holy-grail and dashboard collapse to the stack shape, and the dashboard nav becomes an off-canvas drawer. app-shell moves its nav to the bottom. Set data-layout-nowrap to keep the wide shape. stack, article and landing are already one column.
Named areas
Some sections have no element of their own: a hero, a feature list, a call to action. For these, data-layout-area places a child in an area by name. Only the landing template defines extra areas, so three values work:
| Value |
Use |
hero | The opening section, between the nav and main |
feature | A feature section, after main |
cta | A call to action, before the footer |
<body data-page-layout="landing" data-layout-gap="none"> <header>...</header> <section data-layout-area="hero">Hero content</section> <section data-layout-area="feature">Features grid</section> <section data-layout-area="cta">Call to action</section> <footer>...</footer></body>
In the demo, the solid outlines are the three sections placed by name and the dashed ones are placed by element type. Each prints the area it resolved to. The button moves the call to action to the front of the source: nothing moves on screen, because the template sets the position and not the source order.
That freedom has a cost. Keyboard focus and screen readers follow the source, so keep the source in the order the page reads. A name that the active template does not define has the same effect as an element with no area: the child lands in an extra track with no width and disappears. For the standard regions, use the elements (<nav>, <aside> and so on) and not data-layout-area.
For a complete marketing page built on this template, see the landing page example.
Main level
A <main> with data-layout="sidebar-left" or data-layout="sidebar-right" is a second tier. Only these two values assign main-* areas, and only to direct nav, article and aside children. Use it for a table of contents beside an article, or section navigation inside the content area.
<main data-layout="sidebar-right"> <article> <h1>Page Content</h1> <p>Article body...</p> </article> <aside> <nav>Table of contents</nav> </aside></main>
Which element goes where
| Element |
Grid area |
<nav> | main-nav |
<article> | main-article |
<aside> | main-aside |
Templates
| Template |
Columns |
Use |
sidebar-left | main-nav | main-article | Documentation with sub-navigation |
sidebar-right | main-article | main-aside | Article with table of contents |
These templates adapt in the same way as the page templates: if the nav or aside is absent, the layout falls back to a single column. Below 48rem (unless data-layout-nowrap is set on the main) they stack in the order article, aside, nav, so a leading <nav> moves below the article visually while staying first in the reading order.
Other children of these mains (a <header>, <section> or <footer>) get no area and are auto-placed. For a header/content/footer structure, use regions on an inner element (below).
Component level
Two layouts carry the idea down to a single component. They work on any element and place children by element type, with no named areas.
Regions
data-layout="regions" arranges an element as a column with a header, content and a footer.
<article data-layout="regions" data-layout-gap="m"> <header>Card Title</header> <section><p>Content...</p></section> <footer>Updated 2h ago</footer> </article>
| Child |
Placement |
<header> or [slot="header"] | First |
<section> or [slot="content"] | In DOM order; grows to fill the free space |
<footer> or [slot="footer"] | Last. With no <section> to take the free space, it is pushed to the bottom of an equal-height card |
| Any other child | Between header and footer, in DOM order |
The header and footer are moved visually with order; put them first and last in the source too, so the reading order matches.
A grid of region cards
Regions are most useful inside a grid. The grid makes the cards equal in height, and each card pins its footer to the bottom, so the footers line up however much text a card holds.
<section data-layout="grid" data-layout-min="m" data-layout-gap="m" aria-label="Features"> <article data-layout="regions" data-layout-gap="s"> <header>Performance</header> <section><p>Optimized for speed.</p></section> <footer>Core feature</footer> </article> <article data-layout="regions" data-layout-gap="s"> <header>Accessibility</header> <section><p>WCAG 2.1 AA compliant.</p></section> <footer>Built-in</footer> </article></section>
data-layout="media" places a figure beside its content: an avatar next to a comment, a thumbnail next to a summary.
<article data-layout="media" data-layout-gap="m"> <img src="/src/assets/placeholders/photo-article-compact-1-80x80.svg" alt="" width="48" height="48"> <p><strong>Jane Doe</strong> published a new article about grid identity.</p></article>
| Child |
Placement |
<figure>, <img>, <picture>, <video>, or [slot="figure"] | First column, spanning the content rows |
| Any other child | Second column, one row each, in DOM order |
| Modifier |
Effect |
data-layout-reverse | Figure on the end side (right in left-to-right pages) |
data-layout-align | Vertical alignment: start, center, end, stretch |
data-layout-gap | Gap between figure and content |
Media objects stack vertically when their nearest query container is narrower than 25rem. With data-layout-reverse the figure moves to the end visually; screen readers still meet it first, so keep the figure decorative (alt="") or make sure the order makes sense either way.
All three together
The tiers nest. The page and main tiers use different area names (body-* and main-*), and the component tier places by element type, so nothing clashes.
<body data-page-layout="sidebar-left"> <header>Site Header</header> <nav>Primary Navigation</nav> <main data-layout="sidebar-right"> <article data-layout="regions" data-layout-gap="l"> <header><h1>Article Title</h1></header> <section><p>Article body...</p></section> <footer>Filed under Layout</footer> </article> <aside><nav>Table of Contents</nav></aside> </main> <footer>Site Footer</footer></body>
- Page:
data-page-layout="sidebar-left" on the body places the header, nav, main and footer.
- Main:
data-layout="sidebar-right" on main puts the table of contents beside the article, in main-article and main-aside.
- Component:
data-layout="regions" on the article places its header first, the section in the middle and the footer last.
The demo is that markup. Each box prints how it was placed, and the buttons highlight one tier at a time.
The same nesting in a finished page: the documentation layout example.
Modifiers
These attributes adjust a page layout or its regions.
| Attribute |
Effect |
data-layout-sticky | Sticky header, nav or aside (direct children of a page layout). Requires <html data-sticky>. |
data-layout-bleed | Span all grid columns. Only on direct children of a data-page-layout element. |
data-layout-nowrap | Prevent the responsive collapse to stack |
data-layout-sidebar-width | narrow (12rem), normal (16rem), wide (20rem) sidebar columns |
data-sidebar="collapsed" | Use the collapsed sidebar width (--sidebar-collapsed, default 4rem) |
data-sidebar="hidden" | Hide the sidebar nav and drop its column |
data-layout-area | hero, feature or cta in the landing template |
Container names
The regions are named query containers. A component can ask how wide "the main region" is, by name, and not only how wide its nearest container is.
| In |
Element |
Container name |
data-page-layout | <main> | region-main |
data-page-layout | <nav> | region-nav (only where the nav column has a definite width; see data-page-layout) |
data-page-layout | <aside> | region-aside |
main[data-layout="sidebar-left"] | <nav> | region-main-nav (a nav is not a size container by default; add data-container to query it) |
main[data-layout="sidebar-left"] | <article> | region-main-content |
main[data-layout="sidebar-right"] | <article> | region-main-content |
main[data-layout="sidebar-right"] | <aside> | region-main-aside |
For example, to change a grid when the main region is narrow:
@container region-main (width < 40rem) { .article-grid { grid-template-columns: 1fr; }}
To make any other element a container, use the data-container attribute. Its named presets are card, panel and media; with no value the container has no name.
<li data-container="card"> <p>Content that responds to container width</p></li>
Accessibility
- Grid placement changes where regions appear, not their order in the DOM. Keyboard and screen-reader order follow the source, so write header, nav, main, aside, footer in reading order.
- The page regions are landmarks because of their elements (
main, nav, aside, and header/footer as direct children of body), not because of the grid. Give each nav and aside an aria-label when there is more than one.
- Collapsed mobile layouts and the dashboard drawer are covered on
data-page-layout.