Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

Grid Identity

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.

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
stackOne column. Also what a bare data-page-layout gives.header, nav, main, aside, footer
sidebar-leftNavigation column, then mainheader, nav, main, footer
sidebar-rightMain, then a sidebar columnheader, main, aside, footer
holy-grailThree columns: nav, main, asideheader, nav, main, aside, footer
app-shellA navigation bar the full height of the page, beside header and mainheader, nav, main
dashboardHeader across the top, nav beside main. The nav becomes a drawer on small screens.header, nav, main
articleOne centered column for readingheader, main, footer
landingOne column with extra named areas for marketing sectionsheader, 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.

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
heroThe opening section, between the nav and main
featureA feature section, after main
ctaA call to action, before the footer

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.

Which element goes where

Element Grid area
<nav>main-nav
<article>main-article
<aside>main-aside

Templates

Template Columns Use
sidebar-leftmain-nav | main-articleDocumentation with sub-navigation
sidebar-rightmain-article | main-asideArticle 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.

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 childBetween 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.

Media object

data-layout="media" places a figure beside its content: an avatar next to a comment, a thumbnail next to a summary.

Child Placement
<figure>, <img>, <picture>, <video>, or [slot="figure"]First column, spanning the content rows
Any other childSecond column, one row each, in DOM order
Modifier Effect
data-layout-reverseFigure on the end side (right in left-to-right pages)
data-layout-alignVertical alignment: start, center, end, stretch
data-layout-gapGap 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.

  • 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-stickySticky header, nav or aside (direct children of a page layout). Requires <html data-sticky>.
data-layout-bleedSpan all grid columns. Only on direct children of a data-page-layout element.
data-layout-nowrapPrevent the responsive collapse to stack
data-layout-sidebar-widthnarrow (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-areahero, 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:

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.

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.
↑