layout-card

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

Attributes

Attribute Values Default Description
data-variant default, elevated, outlined, ghost default Visual style variant
data-padding none, s, m, l, xl m Internal padding (applies to children in grid mode)
data-max narrow, content, wide - Max-width constraint for centered card patterns

Block Mode

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

Default

Default Card

Subtle shadow with background color.

data-variant="elevated"

Elevated Card

Stronger shadow for more emphasis.

data-variant="outlined"

Outlined Card

Border instead of shadow.

data-variant="ghost"

Ghost Card

Transparent, no shadow or border.

Code

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

Grid Mode (Structured Cards)

Add <header>, <section>, or <footer> children to automatically activate CSS Grid with named areas. No extra attributes needed — the :has() selector detects semantic children.

Card Title

Card content goes here. This area expands to fill available space.

Code

<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

  • <header> maps to the header grid area with a bottom border
  • <section> maps to the content grid area (expands to fill)
  • <footer> maps to the footer grid area with a top border and flex layout for actions
  • Non-semantic children without a slot attribute are implicitly placed in the content area

Grid Mode Variants

All visual variants work in both block and grid modes.

Default

Subtle shadow, solid background.

Elevated

Stronger shadow for emphasis.

Outlined

Border instead of shadow.

Ghost

Transparent background.

Grid Mode Padding Sizes

The data-padding attribute controls spacing in all grid areas.

Small

Compact padding.

Default

Standard padding.

Large

Spacious padding.

Code

<!-- Small padding --> <layout-card data-padding="s"> <header><h3>Compact</h3></header> <section><p>Small padding for dense layouts.</p></section> <footer><button>OK</button></footer> </layout-card> <!-- Large padding --> <layout-card data-padding="l"> <header><h3>Spacious</h3></header> <section><p>Large padding for prominent content.</p></section> <footer><button>OK</button></footer> </layout-card>

Slot Escape Hatch

Use slot="content" for non-semantic elements that should go in the content grid area.

Quote Card

"The only way to do great work is to love what you do."

Code

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

padding="none"
padding="s" padding="m" (default) padding="l" padding="xl"

Usage Examples

Content Card

Card image

Card Title

A brief description of the card content that provides context for the user.

<layout-card> <layout-stack data-layout-gap="m"> <div data-media data-layout-ratio="16:9" data-radius="s"> <img src="image.jpg" alt="Card image" loading="lazy" /> </div> <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

Product image
Category Product Name $49.99
<layout-card data-variant="outlined"> <layout-stack data-layout-gap="m"> <div data-media data-layout-ratio="1:1" data-radius="s"> <img src="product.jpg" alt="Product image" loading="lazy" /> </div> <layout-stack data-layout-gap="xs"> <small style="color: var(--color-text-muted);">Category</small> <strong>Product Name</strong> <strong style="font-size: var(--font-size-lg);">$49.99</strong> </layout-stack> <button type="button">Add to Cart</button> </layout-stack> </layout-card>

Stat Cards

Total Revenue $45,231 +12.5% from last month Active Users 2,345 +8.2% from last month
<layout-grid data-layout-min="15rem" data-layout-gap="m"> <layout-card data-variant="elevated" data-padding="l"> <layout-stack data-layout-gap="xs"> <small style="color: var(--color-text-muted);">Total Revenue</small> <strong style="font-size: var(--font-size-2xl);">$45,231</strong> <small style="color: var(--color-success);">+12.5% from last month</small> </layout-stack> </layout-card> </layout-grid>

Nested Cards

Outer Card

Nested cards automatically get a raised surface color.

Nested Card

This inner card has a distinct background.

<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

Jane Doe Jane Doe Product Designer UX UI Figma
<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 style="color: var(--color-text-muted);">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

In grid mode, the card uses container-type: inline-size and automatically adjusts padding and typography when placed in narrow containers (under 300px). Headings shrink and footer actions stack vertically.

Accessibility

  • In grid mode, use semantic HTML elements (header, section, footer) for proper document structure
  • 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

CSS Implementation

layout-card { display: block; padding: var(--_padding, var(--size-m)); background: var(--color-surface); border-radius: var(--radius-l); box-shadow: 0 1px 3px oklch(0% 0 0 / 0.1); container-type: inline-size; /* Smart grid mode via :has() */ &:has(> :is(header, section, footer)) { display: grid; grid-template: "header" auto "content" 1fr "footer" auto / 1fr; overflow: hidden; padding: 0; } } /* Grid-mode child styles */ layout-card:has(> :is(header, section, footer)) { > header { grid-area: header; padding: var(--size-m) var(--size-l); } > section { grid-area: content; padding: var(--size-l); } > footer { grid-area: footer; padding: var(--size-m) var(--size-l); } }

Related Elements