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

layout-grid

Auto-fit responsive grid layout. Creates equal-width columns that automatically reflow based on available space.

Overview

A grid fits as many equal-width columns as its width allows, then wraps the rest onto new rows. It is a CSS grid with grid-template-columns: repeat(auto-fit, minmax(min(var(--_min), 100%), 1fr)): every column is at least the minimum width (15rem by default) and the columns share any leftover space equally.

The column count depends on the grid's own width, not the viewport, so the same grid shows more columns in a wide main area than in a narrow sidebar. Items flow in source order, row by row.

Element and attribute forms

Any element can be a grid with data-layout="grid". The same data-layout-* modifiers work on both forms; the two below produce the same columns. A list of items is a natural fit for the attribute form on a <ul>.

Which to choose: use the attribute form when the grid is already a semantic element: a <ul> of products, a <section> of features. Use <layout-grid> when there is no such element 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 grid resolve against it. See data-layout for the full comparison and Semantic Layouts for the approach.

Attributes

Attribute Values Default Applies to Description
data-layout-min xs, s, m, l, xl m both Minimum column width before wrapping: 8 / 10 / 15 / 20 / 25rem. Tracks are clamped to the container, so a grid narrower than the minimum shows one full-width column instead of overflowing. One-off lengths: see the escape hatch.
data-layout-gap none, 3xs, 2xs, xs, s, m, l, xl, 2xl, 3xl m both Gap between cells, on the shared size scale.
data-layout-subgrid (bare), 2, 3, 4 3 (bare) both Each child becomes a subgrid spanning that many rows so header/content/footer align across cells. Bare means 3; any other value also spans 3. See Subgrid.

Custom properties

PropertyDefaultDescription
--layout-min (unset) A minimum column width that beats data-layout-min, set inline: style="--layout-min: 220px". Registered with inherits: false, so a nested grid does not pick it up. <layout-cover> reads the same property as its minimum height.

Child attributes

Every direct child is a cell. With data-layout-subgrid, each child's own direct children become its rows.

Attribute On Applies to Description
data-container main, article, section, aside both With data-layout-subgrid, these children are not query containers, so they can be subgrids. data-container restores the container; the child then sizes its own rows.

Examples

Minimum width

The data-layout-min attribute sets the minimum width each column can shrink to before the grid reflows.

Each track is minmax(min(min-width, 100%), 1fr). In a container narrower than the minimum (an xl grid in a 300px sidebar, or on a phone) the grid shows one column at the container's width instead of overflowing.

One-off widths: --layout-min

When none of the tokens fit, set --layout-min inline on the grid, as in the last example above. It beats the data-layout-min token. It is registered as non-inheriting, so a grid nested inside goes back to its own token or the default. <layout-cover> uses the same property for its minimum height.

Subgrid

With data-layout-subgrid, each child becomes a grid whose rows are subgrid. The child spans 3 rows (bare or "3"), 2, or 4. A header that wraps to two lines in one card then pushes the body row down in every card on that row, so titles, bodies and footers line up.

  • Give each child as many direct children as rows: header, section and footer for the default 3, title and body for 2.
  • The subgridded rows use the grid's row gap. data-layout-gap sets both the space between cards and the space between the parts inside each card. To space the parts differently, set row-gap on the children.
  • <layout-card> children with header/section/footer drop their own row template and follow the subgrid.
  • Any element can be the child: <layout-card>, <li>, or <article>/<section>. VB normally makes main, article, section and aside query containers; as direct children of a subgrid layout they are not, because the layout containment a query container needs would make them independent grids. A child with data-container keeps its container and sizes its own rows instead.
  • Browsers without subgrid fall back to cards that size their own rows.

Gap

The data-layout-gap attribute controls spacing between grid items.

Product grid

Feature cards

Stats grid

Accessibility

  • Items flow in source order, left to right and then row by row (right to left in RTL pages), so reading and focus order match what is on screen. Don't reorder cells with order or explicit grid placement.
  • When the cells are a collection (products, team members, features), use the attribute form on a <ul> so screen readers announce how many items there are. <layout-grid> has no role of its own.
  • Keep heading levels inside cells consistent with the page outline; subgrid alignment is visual only.
  • The column count follows the grid's width, so at high zoom the grid drops to fewer columns instead of scrolling sideways (WCAG 1.4.10 Reflow).

Related

↑