Elevated surface container with background, radius, shadow, and padding. Use the data-canvas attribute on semantic elements or the layout-canvas wrapper element.
Overview
A canvas is a surface: a panel with a background, border radius, shadow and padding that sets a region of the page apart. Several canvases can sit on one page, side by side or nested.
Both forms consume the same --canvas-* design tokens used by data-backdrop, so theme overrides apply to both systems.
The surface always reserves a 1px edge. On a plain page, where the canvas and the page share --color-surface, the edge is a --color-border hairline so the panel reads in light and dark mode. Under data-backdrop the tinted page frames the surface and the edge is transparent. In forced-colours mode (Windows High Contrast) the edge is drawn in CanvasText.
Element and attribute forms
The attribute form is data-canvas, not data-layout="canvas", and the variant goes in its value: data-canvas, data-canvas="flush" or data-canvas="elevated". The element form is <layout-canvas> with data-variant. data-max, data-padding and data-canvas-depth work on both.
1234567891011
<article data-canvas> <h2>Article with a canvas surface</h2> <p>The article itself is the surface: no wrapper element.</p></article> <layout-canvas> <h2>Layout canvas element</h2> <p>The same surface as a wrapper.</p></layout-canvas>
Which to choose: prefer data-canvas on the semantic element that already holds the content (<article>, <section>, <aside>, <form>). Use <layout-canvas> when several children with no common semantic parent need one surface. Note that main, article, section and aside are container-query containers, which <layout-canvas> is not.
Why not data-layout? A canvas is a surface, not a flow layout. VB keeps the two apart: flow primitives (stack, grid, reel…) use data-layout="…" with data-layout-* modifiers, and surfaces (canvas, card, badge) use bare data-* attributes such as data-max and data-padding. That way one element can be both: <article data-canvas data-layout="stack"> is a surface whose children stack.
Attributes
| Attribute |
Values |
Default |
Applies to |
Description |
data-canvas |
(bare), flush, elevated |
(bare) |
attribute |
Turns any element into a canvas. The value is the variant: bare for the default surface, flush (no radius or shadow) or elevated (larger radius and shadow, 37.5rem and wider). See data-canvas. |
data-variant |
flush, elevated |
— |
element |
Variant for <layout-canvas>. Has no effect with data-canvas; put the variant in the data-canvas value instead. elevated applies at 37.5rem and wider. |
data-max |
narrow, normal, wide, prose |
— |
both |
Max inline size, centered: narrow / normal / wide use the --content-narrow / --content-normal / --content-wide tokens (40 / 60 / 80rem by default; normal is fluid under data-fluid), prose is 65ch. |
data-padding |
none, s, m, l, xl |
l |
both |
Padding on all sides. An explicit value is kept on narrow screens (see Mobile behavior). |
data-canvas-depth |
1, 2 |
— |
both |
Stacked-paper effect with 1 or 2 sheets behind the surface. 37.5rem and wider only; not on the flush variant. |
Child attributes
None. Any content can go inside a canvas; a canvas nested in another canvas picks up the raised surface colour automatically.
Examples
Variants
flush drops the radius and shadow for an edge-to-edge surface; elevated adds a larger radius and stronger shadow for emphasis.
123456789101112
<section data-canvas="flush"> <h2>Flush canvas</h2> <p>No border radius or shadow. Edge-to-edge surface.</p></section> <section data-canvas="elevated"> <h2>Elevated canvas</h2> <p>Larger radius and stronger shadow for emphasis.</p></section> <layout-canvas data-variant="elevated">...</layout-canvas>
Width constraints
Use data-max to constrain the canvas width. It auto-centers with margin-inline: auto.
123456789
<article data-canvas data-max="narrow"> <h2>Narrow canvas</h2> <p>Constrained to --content-narrow, centered on the page.</p></article> <article data-canvas data-max="normal"> <h2>Content width</h2> <p>Constrained to --content-normal (fluid under data-fluid).</p></article>
Padding
data-padding sets the padding on all sides, from none to xl (default l).
123456789
<article data-canvas data-padding="s"> <h2>Small padding</h2> <p>For dense surfaces such as toolbars or compact panels.</p></article> <article data-canvas data-padding="xl"> <h2>Extra-large padding</h2> <p>For a spacious, featured surface.</p></article>
Nested canvases
Nested canvases automatically use --color-surface-raised for visual hierarchy. They do it by setting --canvas-bg, not background, so the depth sheets match the nested surface and an author's own --canvas-bg on the nested canvas still wins.
123456789
<article data-canvas> <h2>Outer canvas</h2> <p>Primary surface background.</p> <aside data-canvas aria-labelledby="nested-canvas-heading"> <h3 id="nested-canvas-heading">Nested canvas</h3> <p>Automatically uses the raised surface colour for hierarchy.</p> </aside></article>
Ghost card depth
Add stacked-paper sheets beneath the canvas for a layered effect. Not available on the flush variant, and only drawn at 37.5rem and wider.
123456789
<article data-canvas data-canvas-depth="1"> <h2>Single ghost card</h2> <p>One stacked paper sheet beneath the canvas.</p></article> <article data-canvas data-canvas-depth="2"> <h2>Double ghost cards</h2> <p>Two stacked paper sheets for extra depth.</p></article>
Multiple canvases
Unlike data-backdrop, which styles body-level regions implicitly, data-canvas works on any element, so you can have multiple independent canvases on the same page.
12345678910
<section data-layout="grid" data-layout-min="l"> <article data-canvas> <h2>Canvas A</h2> <p>Independent canvas region.</p> </article> <aside data-canvas="elevated" aria-labelledby="canvas-b-heading"> <h2 id="canvas-b-heading">Canvas B</h2> <p>Elevated variant alongside.</p> </aside></section>
Relationship to data-backdrop
data-canvas and data-backdrop are complementary:
data-backdrop styles body > main/header/footer/nav/aside implicitly
data-canvas is for explicit, per-element canvas surfaces
- Both consume the same
--canvas-* tokens
- A page can use both simultaneously
Token coupling
The --canvas-* tokens (--canvas-bg, --canvas-radius, --canvas-shadow, padding and width) are only defined under [data-backdrop]. Without a backdrop, every canvas uses the fallbacks (surface colour, --radius-l, --shadow-l). With one, the backdrop preset decides: <html data-backdrop="flush"> sets --canvas-radius: 0 and --canvas-shadow: none, which flattens every default data-canvas on the page too. The elevated variant reads --radius-xl and --shadow-xl directly, so it keeps its elevation under any backdrop preset. To restyle one canvas, set the --canvas-* tokens on that element.
Mobile behavior
Below 37.5rem (600px, --bp-s), every canvas goes flush — no border radius, no shadow (including the elevated variant and the depth sheets) — and fills the width with reduced inline padding (--size-m). Two exceptions: an explicit data-padding keeps its value, and an explicit data-max still caps the width (only prose, 65ch, is narrower than the breakpoint). The element and attribute forms behave the same. This matches data-backdrop mobile behavior.
Accessibility
- A canvas is presentation only. It adds no role or name. Choose the element by meaning (
<article> for standalone content, <aside> for related content, <section> with a heading for a region) and the surface follows; that is the main reason to prefer the attribute form.
- Forced colours: Windows High Contrast removes backgrounds and shadows, so the canvas draws its edge in
CanvasText and stays visible as a separate region.
- Contrast: nested canvases use
--color-surface-raised, a theme token designed to carry the theme's text colours. If you set --canvas-bg yourself, check the text contrast against it (4.5:1 for body text, WCAG 1.4.3).
- Edges are not the only cue: on a plain page the 1px hairline marks the edge where the shadow is faint (dark mode). Give each canvas a heading as well, so the regions are distinct for screen reader users too.