apps/www/content/docs/components/card.mdx
import { Card } from "@chakra-ui/react"
<Card.Root>
<Card.Header />
<Card.Body />
<Card.Footer />
</Card.Root>
Use the variant prop to change the visual style of the Card.
Use the Card component within a form to group related fields together.
<ExampleTabs name="card-with-form" />Use the size prop to change the size of the Card.
Use the Card component to display an image.
<ExampleTabs name="card-with-image" />Use the Card component to display content horizontally.
<ExampleTabs name="card-horizontal" />Use the Card component to display an avatar.
<ExampleTabs name="card-with-avatar" />Create a custom Card recipe to add new style variants:
import { defineSlotRecipe } from "@chakra-ui/react"
import { cardAnatomy } from "@chakra-ui/react/anatomy"
const customCardRecipe = defineSlotRecipe({
className: "chakra-card",
slots: cardAnatomy.keys(),
variants: {
// add new variant="ghost"
variant: {
gradient: {
root: {
bg: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
color: "white",
},
},
},
},
})
Add custom size variants to the Card recipe:
const customCardRecipe = defineSlotRecipe({
// ...
variants: {
size: {
// ... existing sizes (sm, md, lg)
xl: {
root: { "--card-padding": "spacing.10" },
title: { textStyle: "2xl" },
},
},
},
})
Set new default values for size and variant:
const customCardRecipe = defineSlotRecipe({
// ...
defaultVariants: {
variant: "elevated", // Default to elevated instead of outline
size: "lg", // Default to lg instead of md
},
})
Add the custom recipe to your theme:
const config = defineConfig({
theme: {
slotRecipes: {
card: customCardRecipe,
},
},
})
const system = createSystem(defaultConfig, config)
export function Provider(props: { children: React.ReactNode }) {
return <ChakraProvider value={system}></ChakraProvider>
}
View the default Card recipe for reference.
Explore the Card component parts interactively. Click on parts in the sidebar
to highlight them in the preview.