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-sidebar

Sidebar layout with a fixed-basis sidebar and a flexible content column that wraps below it when its container is too narrow.

Overview

A sidebar layout puts a fixed-basis sidebar next to a flexible content column, and drops the content below the sidebar when there is no longer room for both. It is a wrapping flex row (display: flex; flex-wrap: wrap): the sidebar takes its basis and the content grows into the rest.

How the sidebar is chosen. The layout is semantic-aware. <nav> and <aside> children are the sidebar; every other child is content. That lets you write children in their natural DOM order and pick the visual side with data-layout-side. Injected helpers are never content: hr, [role="separator"] (the data-splitter divider), template, script and style children are skipped, so an <hr> between the columns does not become a third column.

When there is no nav or aside child, a positional fallback applies: the first child is the sidebar and the last child is the content.

When it wraps. Wrapping depends on the width of the container, not the viewport. The sidebar takes its basis (16rem by default) and the content column takes the rest; when the content would drop below its floor (data-layout-content-min, 50% by default) it wraps underneath. A sidebar inside a narrow card wraps even on a wide screen. Inside the <main> of a data-page-layout page, once that <main> is narrower than 40rem, every child of the sidebar takes a full row (in both forms) unless the sidebar has data-layout-nowrap.

Element and attribute forms

Any element can be a sidebar layout with data-layout="sidebar". The same rules and data-layout-* modifiers apply to both forms; the two below are identical, at every width.

Which to choose: use the attribute form when a semantic element is already the two-column region: a <section> of the page, or a <main> that holds its own navigation. Use <layout-sidebar> 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 layout resolve against it. See data-layout for the full comparison and Semantic Layouts for the approach.

Nested sidebars start from their own defaults: an inner sidebar never inherits the outer one's gap or width settings.

Attributes

Attribute Values Default Applies to Description
data-layout-gap none, 3xs, 2xs, xs, s, m, l, xl, 2xl, 3xl m both Gap between the columns, on the shared size scale.
data-layout-side end start (omit the attribute) both end: put the sidebar on the end side. There is no start value; the start side is what you get without the attribute. nav/aside children keep DOM order (order: 1); the positional fallback reverses the row (see Accessibility).
data-layout-sidebar-width narrow, normal, wide normal both Sidebar basis: 12 / 16 / 20rem (the same three values in every sidebar context).
data-layout-content-min s, m, l m both Content column floor before wrapping: 40 / 50 / 60%. One-off: style="--layout-content-min: 45%".
data-layout-nowrap (boolean) — both Never wrap; the sidebar stays beside the content, also in a narrow page region.

Custom properties

PropertyDefaultDescription
--layout-content-min (unset) A content floor that beats data-layout-content-min, set inline: style="--layout-content-min: 45%". Registered with inherits: false, so a nested sidebar does not pick it up.

Child attributes

Attribute On Applies to Description
data-layout-sticky nav, aside both Sticky sidebar with its own scroll, active when the page opts into the smart sticky system (<html data-sticky>). See Sticky sidebar.

Examples

Side

The sidebar sits on the start side by default (left in a left-to-right page). data-layout-side="end" moves it to the end side; there is no start value, so omit the attribute for the start side. With nav/aside children, write the content first and the sidebar second so the DOM order matches what is on screen.

Width

The data-layout-sidebar-width attribute controls the sidebar width.

Content minimum

data-layout-content-min sets how narrow the content column may get (40 / 50 / 60%) before it wraps below the sidebar. For a one-off value, set --layout-content-min inline, for example style="--layout-content-min: 45%"; it beats the attribute and does not reach nested sidebars.

No wrap

data-layout-nowrap keeps the sidebar beside the content at every width, including inside a narrow page region. Use it when the sidebar is small, such as an icon rail.

Sticky sidebar

Add data-layout-sticky to the nav or aside to pin it while the content scrolls. It has two prerequisites:

  • The page opts into the smart sticky system with <html data-sticky>. Without it the attribute does nothing.
  • The sticky child must be a nav or aside that is a direct child of the sidebar layout.

The sidebar is limited to the remaining viewport height and scrolls on its own when its content is taller.

Resizable panels

Add data-splitter to make the sidebar resizable with a draggable, keyboard-accessible divider. The splitter switches the layout to no-wrap and lets the content column shrink freely.

Gap

The data-layout-gap attribute controls spacing between sidebar and main content.

Dashboard layout

Article with related content

Filters layout

Accessibility

  • Keep DOM order the same as the visual order. For a sidebar on the end, write the content first and the <aside> after it, then set data-layout-side="end". If the aside comes first in the source, the layout still moves it to the end visually, but focus and reading order then differ from what is on screen (WCAG 1.3.2, 2.4.3).
  • In the positional fallback (no nav or aside child), data-layout-side="end" reverses the whole row with flex-direction: row-reverse, so the visual order always differs from the DOM order. Prefer nav/aside children, which keep DOM order.
  • Give a nav sidebar an accessible name (aria-label or aria-labelledby) when the page has more than one navigation region.
  • A sticky sidebar scrolls on its own when it is taller than the viewport. Keep focusable content (links) in it, so keyboard users can scroll it by moving focus.
  • The data-splitter divider is a focusable separator that resizes with the arrow keys.

Related

↑