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

Container component with background, padding, and visual variants. Simple block mode by default; add header/section/footer children to activate structured mode.

Overview

<layout-card> is a card surface with two modes. In block mode (the default) it is a padded block with a background, radius and shadow. Give it a <header>, <section> or <footer> child and it switches to structured mode: header pinned on top, footer pinned at the bottom, content stacked between, so footers line up across a row of cards.

A card nested in another card gets the raised surface colour automatically, and in forced-colours mode every card except ghost draws a CanvasText border.

Element and attribute forms

Element only. There is no data-layout="card" or data-card attribute. The structured mode depends on the card owning its header, content and footer children, so it is a component, not a layout you can lay over any element.

Alternatives when you want a card look on an existing element:

  • For a surface on a semantic element, use data-canvas: <article data-canvas> gives an article a background, radius, shadow and padding without a wrapper. See <layout-canvas>.
  • For a collection of cards (a grid, a list, a reel), use <card-list>.
  • To lay out the content inside a card, put a layout on a child: <section data-layout="stack">. See data-layout.

Attributes

Attribute Values Default Applies to Description
data-variant elevated, outlined, ghost — element Visual style: elevated (shadow), outlined (border), ghost (no surface).
data-padding none, s, m, l, xl m element Internal padding. In structured mode the children are padded one step larger (see padding scale).
data-max narrow, normal, wide, prose — element Max inline size, centered in normal block flow (margin-inline: auto) and in flex/grid parents: --content-narrow / --content-normal / --content-wide, or prose (65ch). Same keyword set as layout-center and canvas.

Built-in behaviour

  • Nested cards: a card inside another card uses --color-surface-raised, so it stands out from its parent.
  • Forced colours: every card except ghost gets a CanvasText border, because the system removes the shadow and background that mark its edges.
  • Container queries: only a structured card is a size container; see Container queries.

Child attributes

Attribute or elementOnDescription
<header>, slot="header" a direct child Pinned to the top with a bottom border. Switches the card to structured mode.
<footer>, slot="footer" a direct child Pinned to the bottom with a top border and a wrapping row for actions. Switches the card to structured mode.
<section>, slot="content" a direct child Content. Switches the card to structured mode; in structured mode every other child is content too.

Examples

Block mode

By default, layout-card is a simple block container with padding. Use it for any content that just needs a card surface.

Structured mode

Add a <header>, <section>, or <footer> child, or any child with slot="header", slot="content" or slot="footer", and the card switches to structured mode. No extra attributes are needed: the :has() selector detects the children.

How it works

  • The <header> (or slot="header") is pinned to the top and gets a bottom border.
  • The <footer> (or slot="footer") is pinned to the bottom, so footers line up when cards in a grid stretch to equal height. It gets a top border and a wrapping flex row for actions.
  • Every other child is content. Content children stack in source order between the header and footer, one body padding apart. A <p> followed by a <section> is fine, and nothing overlaps.
  • In structured mode the card is a size container (container-type: inline-size), which powers the compact rule below. A block-mode card is not a container, so it can shrink to fit its content inside a cluster or a centered stack.

Multiple content children and slot-only cards

Aligning cards with subgrid

Inside <layout-grid data-layout-subgrid>, or its attribute form data-layout="grid" data-layout-subgrid, each structured card spans three parent rows, so headers, content and footers line up across siblings. The header takes the first row, the footer the last, and content fills the rows between. Use one content child per spare row (one for the default span of 3), or wrap several in a <section>. The cards must be direct children of the grid.

Structured mode variants

All visual variants work in both block and structured modes.

Structured mode padding sizes

In structured mode the card itself has no padding. Each child is padded one step up the scale from the block-mode value, so data-padding="m" (the default) gives the header and footer --size-m block and --size-l inline padding, and content --size-l. none also removes the header and footer dividers.

data-paddingBlock modeHeader / footerContent
none000
s--size-s--size-xs / --size-s--size-s
m (default)--size-m--size-m / --size-l--size-l
l--size-l--size-l / --size-xl--size-xl
xl--size-xl--size-xl / --size-2xl--size-2xl

Each card declares its own padding values, so a nested card never inherits its parent's data-padding.

Slot escape hatch

Use slot="header", slot="content" or slot="footer" to give any element one of the structured roles. Children without a slot are already content, so slot="content" is mainly useful to switch a card into structured mode when it has no header, section or footer.

Padding variants (block mode)

The data-padding attribute controls the internal spacing.

Content card

Product card

Stat cards

Nested cards

Profile card

Container queries

Only in structured mode, the card uses container-type: inline-size. When the card is narrower than 300px, every child's padding is capped at --size-s, header headings shrink, and footer actions stack vertically. A structured card is a size container, so give it a width (or data-max) when it is a shrink-to-fit item, for example inside <layout-cluster>.

Accessibility

  • In structured mode, use semantic HTML elements (header, section, footer) for proper document structure
  • The header and footer are pinned visually with order. Keep them first and last in the source too, so reading and focus order match what is on screen.
  • In forced-colors mode, every card except ghost gets a CanvasText border, because the system removes the shadow and background that mark its edges.
  • Include headings in the header area for screen reader navigation
  • Footer actions should be keyboard accessible
  • Consider wrapping in article if the card represents standalone content

Related

↑