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.
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.
123456789101112131415
<layout-card> Default card with subtle shadow</layout-card> <layout-card data-variant="elevated"> Elevated card with stronger shadow</layout-card> <layout-card data-variant="outlined"> Outlined card with border</layout-card> <layout-card data-variant="ghost"> Ghost card with no background</layout-card>
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.
12345678910
<layout-card> <header><h3>Card Title</h3></header> <section> <p>Content with automatic grid placement.</p> </section> <footer> <button type="button" class="secondary">Cancel</button> <button type="button">Save</button> </footer></layout-card>
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
1234567891011121314
<layout-card> <header><h2>Release notes</h2></header> <p>Version 2.4 ships offline drafts and faster search.</p> <section> <h3>Fixed</h3> <p>Attachments no longer duplicate after a sync conflict.</p> </section> <footer><button type="button">Read more</button></footer></layout-card> <layout-card data-variant="outlined"> <h2 slot="header">Slot-only card</h2> <p slot="content">The slots alone switch the card to structured mode.</p></layout-card>
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.
123456789101112131415161718
<layout-grid data-layout-min="s" data-layout-gap="m" data-layout-subgrid> <layout-card data-variant="outlined"> <header><h2>Starter</h2></header> <section><p>For a single project.</p></section> <footer><button type="button">Choose Starter</button></footer> </layout-card> <layout-card data-variant="outlined"> <header><h2>Team plan with a longer name</h2></header> <section><p>Longer copy that takes more lines.</p></section> <footer><button type="button">Choose Team</button></footer> </layout-card></layout-grid> <section data-layout="grid" data-layout-min="s" data-layout-gap="m" data-layout-subgrid aria-label="Plans"> <layout-card>...</layout-card> <layout-card>...</layout-card></section>
Structured mode variants
All visual variants work in both block and structured modes.
123456789101112131415161718
<layout-grid data-layout-min="m" data-layout-gap="m"> <layout-card> <header><h2>Default</h2></header> <section><p>Subtle shadow, solid background.</p></section> </layout-card> <layout-card data-variant="elevated"> <header><h2>Elevated</h2></header> <section><p>Stronger shadow for emphasis.</p></section> </layout-card> <layout-card data-variant="outlined"> <header><h2>Outlined</h2></header> <section><p>Border instead of shadow.</p></section> </layout-card> <layout-card data-variant="ghost"> <header><h2>Ghost</h2></header> <section><p>Transparent background.</p></section> </layout-card></layout-grid>
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-padding | Block mode | Header / footer | Content |
none | 0 | 0 | 0 |
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.
12345678910111213
<layout-card data-padding="s"> <header><h3>Compact</h3></header> <section><p>Small padding for dense layouts.</p></section> <footer><button type="button">OK</button></footer></layout-card> <layout-card data-padding="l"> <header><h3>Spacious</h3></header> <section><p>Large padding for prominent content.</p></section> <footer><button type="button">OK</button></footer></layout-card>
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.
123456
<layout-card> <header><h3>Quote Card</h3></header> <blockquote slot="content"> "The only way to do great work is to love what you do." </blockquote></layout-card>
Padding variants (block mode)
The data-padding attribute controls the internal spacing.
12345
<layout-card data-variant="outlined" data-padding="none">...</layout-card><layout-card data-variant="outlined" data-padding="s">...</layout-card><layout-card data-variant="outlined" data-padding="m">...</layout-card> <layout-card data-variant="outlined" data-padding="l">...</layout-card><layout-card data-variant="outlined" data-padding="xl">...</layout-card>
Content card
123456789101112131415
<layout-card> <layout-stack data-layout-gap="m"> <figure data-media data-ratio="16:9" data-radius="s"> <img src="image.jpg" alt="Card image" loading="lazy" /> </figure> <layout-stack data-layout-gap="xs"> <h3>Card Title</h3> <p>Brief description of the card content.</p> </layout-stack> <layout-cluster data-layout-gap="s"> <button type="button">Primary</button> <button type="button" class="secondary">Secondary</button> </layout-cluster> </layout-stack></layout-card>
Product card
12345678910111213
<layout-card data-variant="outlined"> <layout-stack data-layout-gap="m"> <figure data-media data-ratio="1:1" data-radius="s"> <img src="product.jpg" alt="Product image" loading="lazy" /> </figure> <layout-stack data-layout-gap="xs"> <small>Category</small> <strong>Product Name</strong> <strong>$49.99</strong> </layout-stack> <button type="button">Add to Cart</button> </layout-stack></layout-card>
Stat cards
123456789
<layout-grid data-layout-min="m" data-layout-gap="m"> <layout-card data-variant="elevated" data-padding="l"> <layout-stack data-layout-gap="xs"> <small>Total Revenue</small> <strong>$45,231</strong> <small>+12.5% from last month</small> </layout-stack> </layout-card></layout-grid>
Nested cards
123456789
<layout-card data-padding="l"> <layout-stack data-layout-gap="m"> <h3>Outer Card</h3> <p>Nested cards get a raised surface color.</p> <layout-card> <strong>Nested Card</strong> </layout-card> </layout-stack></layout-card>
Profile card
12345678910111213141516
<layout-card data-variant="outlined"> <layout-stack data-layout-gap="m" data-layout-align="center"> <user-avatar data-size="xl"> <img src="avatar.jpg" alt="Jane Doe" /> </user-avatar> <layout-stack data-layout-gap="xs" data-layout-align="center"> <strong>Jane Doe</strong> <small>Product Designer</small> </layout-stack> <layout-cluster data-layout-gap="xs"> <layout-badge>UX</layout-badge> <layout-badge>UI</layout-badge> <layout-badge>Figma</layout-badge> </layout-cluster> </layout-stack></layout-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>.