Skip to content

Material 3

Components

Card

Cards display content and actions about a single subject.

9:30
For you
Eye Rhymes
Glass & Grace
Night Drive
Luna Park plays the whole record live, with two new songs.

Cards display content and actions about a single subject. Use a card to contain related elements, such as:

  • Images
  • Headlines and supporting text
  • Buttons
  • Lists and other components

To show a set of items of the same kind, such as messages or contacts, use a list instead.

import { Card } from '@material-web/react'

Basic card

Write the content of a card as its children, and choose its look with variant. A card is a container only, and adds no behavior.

Eye Rhymes
Glass & Grace
import { Button, Card } from '@material-web/react'

const cover = `data:image/svg+xml,${encodeURIComponent(
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 140"><rect width="320" height="140" fill="#E8DEF8"/><path d="M0 120 90 60 150 100 200 75 320 125V140H0Z" fill="#6750A4" opacity=".6"/><circle cx="250" cy="40" r="20" fill="#6750A4"/></svg>',
)}`

export default function Basic() {
  return (
    <Card variant="outlined" className="w-80">
      <img src={cover} alt="" className="h-35 w-full object-cover" />
      <div className="p-space-200">
        <div className="text-title-md">Eye Rhymes</div>
        <div className="text-body-md text-on-surface-variant">Glass & Grace</div>
      </div>
      <div className="flex justify-end gap-space-100 p-space-200 pt-0">
        <Button variant="text">Share</Button>
        <Button>Play</Button>
      </div>
    </Card>
  )
}

The Card comes in three variants: elevated (the default), filled and outlined. The three differ in style only, so choose the one that suits your design.

Elevated
A drop shadow lifts it off the background.
Filled
A fill sets it subtly apart from the background.
Outlined
A visual boundary runs around the container.
import { Card } from '@material-web/react'

export default function Variants() {
  return (
    <>
      <Card variant="elevated" className="w-52 p-space-200">
        <div className="text-title-md">Elevated</div>
        <div className="text-on-surface-variant">A drop shadow lifts it off the background.</div>
      </Card>
      <Card variant="filled" className="w-52 p-space-200">
        <div className="text-title-md">Filled</div>
        <div className="text-on-surface-variant">
          A fill sets it subtly apart from the background.
        </div>
      </Card>
      <Card variant="outlined" className="w-52 p-space-200">
        <div className="text-title-md">Outlined</div>
        <div className="text-on-surface-variant">A visual boundary runs around the container.</div>
      </Card>
    </>
  )
}

Elevated card

An elevated card has a shadow, which sets it further apart from the background than a filled card, and less than an outlined one.

Eye Rhymes
Glass & Grace
import { Button, Card } from '@material-web/react'

export default function Elevated() {
  return (
    <Card variant="elevated" className="w-80">
      <div className="p-space-200">
        <div className="text-title-md">Eye Rhymes</div>
        <div className="text-on-surface-variant">Glass & Grace</div>
      </div>
      <div className="flex justify-end p-space-200 pt-0">
        <Button variant="tonal">Play</Button>
      </div>
    </Card>
  )
}

Filled card

A filled card has a fill that sets it subtly apart from the background, with less emphasis than the other two.

Warped Speed
Trapezoid
import { Button, Card } from '@material-web/react'

export default function Filled() {
  return (
    <Card variant="filled" className="w-80">
      <div className="p-space-200">
        <div className="text-title-md">Warped Speed</div>
        <div className="text-on-surface-variant">Trapezoid</div>
      </div>
      <div className="flex justify-end p-space-200 pt-0">
        <Button>Play</Button>
      </div>
    </Card>
  )
}

Outlined card

An outlined card has an outline, which can give it more emphasis than the other two.

Personal Voice
Decorations
import { Button, Card } from '@material-web/react'

export default function Outlined() {
  return (
    <Card variant="outlined" className="w-80">
      <div className="p-space-200">
        <div className="text-title-md">Personal Voice</div>
        <div className="text-on-surface-variant">Decorations</div>
      </div>
      <div className="flex justify-end p-space-200 pt-0">
        <Button>Play</Button>
      </div>
    </Card>
  )
}

Content

A card shows its children in a column, in the order written: an image that reaches the card's edges, padded text, a row of buttons. It clips its content to its rounded corners.

  • Padding: A card has no padding. Add your own to its children, such as p-space-200 for 16dp from its sides.
  • Size: A card is as tall as its content. Like any <div>, it fills the width of a block container and fits its content in a flex row. Give it a width with a class, such as w-80.
  • Direction: Add flex-row to lay the children out in a row.
  • Text: Text in a card has the text-body-md style and the on-surface color. Give a headline its own style, such as text-title-md.
  • Children: The children of a card cannot be a function.

Media

Write an image as a child of the card, with a height and w-full object-cover. It reaches the card's edges, and the card clips it to its rounded corners.

Warped Speed
Recorded over one winter in a lighthouse.
import { Card } from '@material-web/react'

const cover = `data:image/svg+xml,${encodeURIComponent(
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 180"><rect width="320" height="180" fill="#FFD8E4"/><path d="M0 150 90 80 150 130 200 100 320 160V180H0Z" fill="#7D5260" opacity=".6"/><circle cx="250" cy="50" r="22" fill="#7D5260"/></svg>',
)}`

export default function Media() {
  return (
    <Card variant="filled" className="w-80">
      <img src={cover} alt="" className="h-45 w-full object-cover" />
      <div className="p-space-200">
        <div className="text-title-md">Warped Speed</div>
        <div className="text-on-surface-variant">Recorded over one winter in a lighthouse.</div>
      </div>
    </Card>
  )
}

UI controls

A card can hold controls, such as buttons and icon buttons. Each one is a tab stop of its own. This card lays its children out in a row with flex-row, with the playback controls beside the cover.

Eye Rhymes
Glass & Grace
import { Card, Icon, IconButton } from '@material-web/react'

const cover = `data:image/svg+xml,${encodeURIComponent(
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 160"><rect width="160" height="160" fill="#E8DEF8"/><circle cx="80" cy="80" r="44" fill="#6750A4" opacity=".6"/><circle cx="80" cy="80" r="12" fill="#E8DEF8"/></svg>',
)}`

export default function Controls() {
  return (
    <Card variant="filled" className="w-88 flex-row">
      <div className="flex flex-1 flex-col justify-between">
        <div className="p-space-200">
          <div className="text-title-md">Eye Rhymes</div>
          <div className="text-on-surface-variant">Glass & Grace</div>
        </div>
        <div className="flex items-center gap-space-50 p-space-100">
          <IconButton aria-label="Previous">
            <Icon name="skip_previous" />
          </IconButton>
          <IconButton variant="filled" aria-label="Play">
            <Icon name="play_arrow" />
          </IconButton>
          <IconButton aria-label="Next">
            <Icon name="skip_next" />
          </IconButton>
        </div>
      </div>
      <img src={cover} alt="" className="w-35 object-cover" />
    </Card>
  )
}

Primary action

A card itself cannot be pressed. To give a card a primary action, such as a link to a detail page, wrap the content that the action covers in a link or a button of your own inside the card:

  • Position it with relative and add a Ripple as its direct child, for the hover and focus layer and the press ripple.
  • Add the focus-ring-inset class for the focus indicator. It is drawn inside the element, where the card does not clip it.
import { Button, Card, Ripple } from '@material-web/react'

const cover = `data:image/svg+xml,${encodeURIComponent(
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 140"><rect width="320" height="140" fill="#E8DEF8"/><path d="M0 120 90 60 150 100 200 75 320 125V140H0Z" fill="#6750A4" opacity=".6"/><circle cx="250" cy="40" r="20" fill="#6750A4"/></svg>',
)}`

export default function PrimaryAction() {
  return (
    <Card variant="outlined" className="w-80">
      <a
        href="#primary-action"
        className="relative focus-ring-inset flex flex-col text-on-surface no-underline outline-none"
      >
        <Ripple />
        <img src={cover} alt="" className="h-35 w-full object-cover" />
        <div className="p-space-200">
          <div className="text-title-md">Eye Rhymes</div>
          <div className="text-on-surface-variant">Glass & Grace</div>
        </div>
      </a>
      <div className="flex justify-end p-space-200 pt-0">
        <Button variant="text">Share</Button>
      </div>
    </Card>
  )
}

Write the card's other buttons outside the primary action, so that each one stays a control and a tab stop of its own.

Collections

Show cards together in a grid, a vertical list or a carousel, at most 8dp apart (gap-space-100).

Eye Rhymes
Glass & Grace
Warped Speed
Trapezoid
Personal Voice
Decorations
NBR
21st Century Strangers
import { Card } from '@material-web/react'

const cover = (fill: string, ink: string) =>
  `data:image/svg+xml,${encodeURIComponent(
    `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 120"><rect width="240" height="120" fill="${fill}"/><circle cx="180" cy="40" r="20" fill="${ink}"/></svg>`,
  )}`

const albums = [
  { title: 'Eye Rhymes', artist: 'Glass & Grace', cover: cover('#E8DEF8', '#6750A4') },
  { title: 'Warped Speed', artist: 'Trapezoid', cover: cover('#FFD8E4', '#7D5260') },
  { title: 'Personal Voice', artist: 'Decorations', cover: cover('#FFD8E4', '#7D5260') },
  { title: 'NBR', artist: '21st Century Strangers', cover: cover('#E8DEF8', '#6750A4') },
]

export default function Collection() {
  return (
    <div className="grid w-full max-w-120 grid-cols-2 gap-space-100">
      {albums.map((album) => (
        <Card key={album.title} variant="filled">
          <img src={album.cover} alt="" className="h-30 w-full object-cover" />
          <div className="p-space-200">
            <div className="text-title-md">{album.title}</div>
            <div className="text-on-surface-variant">{album.artist}</div>
          </div>
        </Card>
      ))}
    </div>
  )
}

Customization

Pass classes in className to restyle one card. A class of yours replaces the card's own class for the same property. See Styling for the classes and the theme.

Glass & Grace
Live at the lighthouse, Friday at 8 PM.
import { Button, Card } from '@material-web/react'

export default function Custom() {
  return (
    <Card
      variant="filled"
      className="w-80 rounded-shape-xl bg-tertiary-container text-on-tertiary-container"
    >
      <div className="p-space-300">
        <div className="text-title-lg">Glass & Grace</div>
        <div>Live at the lighthouse, Friday at 8 PM.</div>
      </div>
      <div className="flex justify-end p-space-300 pt-0">
        <Button className="bg-tertiary text-on-tertiary">Get tickets</Button>
      </div>
    </Card>
  )
}
  • Color: Pass a container color role and its on-color, such as bg-tertiary-container text-on-tertiary-container.
  • Shape: A card has 12dp corners. Pass a class of the corner scale for another radius, such as rounded-shape-xl.
  • Elevation: Pass an elevation level for another shadow, such as shadow-elevation-3.
  • States: A card reports no state, so className and style take a value and cannot be a function.
  • Every card: To restyle all the cards at once, change the theme.