Card
Card sets one object apart from the rest of the page, such as a project, a plan or a group of settings.
Card sets one object apart from the rest of the page, such as a project, a plan or a group of settings. It has a solid fill, a rounded corner and padding, and it holds whatever you put inside it. Arrange that content with Stack and Flex.
To hold several cards in one region, or to make a quieter region inside a card, use a Surface. For code inside a card, use a CodeBlock. Don't put a card inside another card, and a development build warns you if you do.
size sets the padding and the corner. The content decides how tall the card is. Whether cards cast a shadow is set for the whole app by the Theme's depth.
The element you pass to render decides what the card does. As an <a> or a <button>, the whole card is pressable, with the same hover, press, focus and disabled states as other controls. As a <label> around a Radio or a Checkbox, the whole card selects that control, and the card's edge turns the accent colour while the control is checked.
A card clips its content to its corner. To make a picture or a band reach the card's edge, put it in a Box with m="bleed", or with mt="bleed" and mx="bleed" for the top and sides only.
Set backdrop when an image, a map or a scrolling feed shows behind the card, so that it uses the theme's material. Without it, the card is solid. A card can only be focused when you render it as a link, a button or a label, and a screen reader then reads it as that element, so write its text to make sense read aloud as one name.
- Surface when a quiet region holds several things without making any one of them an object.
Props
Generated from the types. It lists what this component DECLARES: a prop that arrives from a shared type or from the platform is real and is not repeated here.
| Prop | Type | What it does |
|---|---|---|
backdrop? | boolean | Set backdrop when content passes behind the card, such as an image, a canvas or a scrolling feed. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
render? | RenderElement | Renders the card as a different element, which decides what the card does. |
size? | "1" | "2" | "3" | "4" | Sets the padding and the corner size. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <div>.
- A
selectedprop, and aninteractiveone — The element decides what a card does. Use<Card render={<button />}>for a card you press, or put aRadioin<Card render={<label />}>for a card you select. - A card inside a card — A card inside a card doesn't show any clear relationship between the two. Use a Surface for a quieter region inside a card, or to hold several cards.
- A material prop — The Theme sets one material for the whole app. Set
backdropon a card that has content behind it, or wrap part of the page in a nested Theme to change the material there. - Tone, emphasis and bordered — A card is a container, not an action, so it has no rank among its neighbours. Its fill and border are the same on every card in your app.
- A media or cover slot — A card already clips its children to its corner, so a picture can reach the edge without a slot. Wrap it in
<Box mt="bleed" mx="bleed">. - Header and footer slots — A title or a footer is just a layout, so you arrange it yourself with Stack and Flex. That leaves you free to build whatever layout the card needs.