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

Full-height container with vertically centered principal element. Perfect for hero sections, landing pages, and full-viewport layouts.

Overview

A cover fills at least a given height (the full viewport by default) and centres one principal child vertically in it, with optional content pinned to the top and bottom. It is a flex column (display: flex; flex-direction: column) with a min-block-size, so it grows with its content instead of clipping it.

How children are placed. The child with data-layout-principal gets margin-block: auto, which centres it in the free space. A <header> (or any child with data-layout-cover-top) is pushed to the top and a <footer> (or data-layout-cover-bottom) to the bottom. A sole child centres itself without any attribute. With two or more children and no principal, no child is centred on purpose: plain children stack from the top, and a pinned header and footer only split the free space between them. Mark the principal explicitly.

The xl height is 100dvh, not 100vh: dynamic viewport units track the mobile browser chrome, so a full-height cover is not cropped on phones.

Element and attribute forms

Any element can be a cover with data-layout="cover". The same data-layout-* modifiers and child attributes work on both forms; the two below are identical.

Which to choose: use the attribute form when a semantic element is already the full-height region: usually the page's <main> or a hero <section>. Use <layout-cover> 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 cover 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 s, m, l, xl, auto xl both Minimum block size: 50 / 70 / 80vh, xl = 100dvh, auto = none. One-off: style="--layout-min: 65vh" (see Custom height).
data-layout-padding none, s, m, l, xl m both Padding on all sides.
data-layout-gap none, 3xs, 2xs, xs, s, m, l, xl, 2xl, 3xl none both Minimum space between all children (top, principal, bottom), on the shared size scale. The principal's auto margins still centre it. See Gap and centering.
data-layout-centered (boolean) — both Center the principal and text horizontally; header/footer (and data-layout-cover-top/-bottom) children still span the full width.

Custom properties

PropertyDefaultDescription
--layout-min (unset) A minimum height that beats data-layout-min. Set it inline: style="--layout-min: 65vh". Registered with inherits: false, so it does not reach nested layouts. <layout-grid> reads the same property as its minimum column width.

Child attributes

Attribute On Applies to Description
data-layout-principal any child both The vertically centered principal element. A sole child auto-centers without it.
data-layout-cover-top any child both Pin to the top (a <header> child is pinned automatically).
data-layout-cover-bottom any child both Pin to the bottom (a <footer> child is pinned automatically).
data-container main, article, section, aside both With data-layout-centered, the layout removes container-type from semantic children so they size to their content instead of collapsing; this opts one back into container queries (give it a width).

Examples

Basic usage

The cover vertically centres its principal element while the header and footer stay at their edges.

The demo uses data-layout-min="auto" with a fixed height so it fits the preview frame.

Height

The data-layout-min attribute controls the minimum height of the cover.

The demo omits xl because a full-viewport cover fills the whole preview frame.

Custom height

For a one-off height that no token matches, set --layout-min inline on the cover, as in the last cover of the height demo above. It wins over data-layout-min, and because it is registered with inherits: false it does not leak into a nested cover or grid. This is the same escape hatch <layout-grid> uses for its minimum column width, and the conformance checker allows it as an inline style.

A stylesheet rule that sets --layout-min on the cover works too, when the same height is reused.

Padding

The data-layout-padding attribute controls internal spacing.

Gap and centering

Without modifiers the principal is centred vertically but keeps the start alignment of the line. data-layout-centered centres it horizontally too and centres the text, while the header and footer keep the full width (they stretch, so a brand/nav row inside them can still spread out). data-layout-gap sets a minimum space between all children; it shows when the cover is short, as with data-layout-min="auto", because the auto margins otherwise take up all the free space.

Hero section

With data-layout-centered the principal shrinks to its content and centres, while the <header> and <footer> keep the full width — so the header can carry its own data-layout="cluster" and spread the brand and nav with justify="between", with no wrapper inside it. (The demo uses data-layout-min="auto" and a fixed height to fit the preview frame.)

Login page

Error page (404)

The page's <main> carries the layout, so no wrapper is needed, and it fills the viewport with the default xl height. Go Home navigates, so it is a link styled as a button, not a <button>.

Custom top and bottom elements

Accessibility

  • The cover positions children with margins only; it never reorders them, so reading and focus order follow the DOM. Write the header, principal and footer in that order.
  • The height is a minimum, not a fixed size: when text is enlarged or the viewport is short, the cover grows instead of clipping its content (WCAG 1.4.10 Reflow, 1.4.4 Resize Text). Avoid adding overflow: hidden or a fixed height.
  • In the attribute form on <main>, a <header> or <footer> inside it is scoped to the main content and is not exposed as the page's banner or contentinfo landmark. Keep the site header and footer outside <main>.
  • Put the page's <h1> in the principal when the cover is the page (a landing or 404 page), and use links, not buttons, for navigation actions.

Related

↑