Card
A container with a header, content and footer.
Plain HTML
<script setup lang="ts">
import { Button } from '@/components/ui/button';
import * as Card from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
</script>
<template>
<div class="cards">
<Card.Root>
<Card.Header>
<Card.Title>Login to your account</Card.Title>
<Card.Description>Enter your email below to login.</Card.Description>
<Card.Action><Button variant="link">Sign up</Button></Card.Action>
</Card.Header>
<Card.Content>
<div class="field">
<Label for="card-email">Email</Label>
<Input id="card-email" type="email" placeholder="you@example.com" />
</div>
</Card.Content>
<Card.Footer>
<Button>Login</Button>
<Button variant="outline">Cancel</Button>
</Card.Footer>
</Card.Root>
<Card.Root size="sm" style="--dui-card-radius: 0">
<Card.Header>
<Card.Title>Small card</Card.Title>
<Card.Description>Tighter spacing, and square corners set from outside.</Card.Description>
</Card.Header>
<Card.Content>Content goes here.</Card.Content>
</Card.Root>
</div>
</template>
<style scoped>
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
align-items: start;
gap: var(--dui-space-4);
width: min(100%, 34rem);
}
.field {
display: grid;
gap: var(--dui-space-2);
}
</style>
Installation
npx distill-ui add card- Set up the tokens once, if you haven't: see manual installation.
- Copy these files into your project:
<script setup lang="ts">
const { size = 'md' } = defineProps<{ size?: 'sm' | 'md' }>();
</script>
<template>
<div class="card" :data-size="size"><slot /></div>
</template>
<!--
Options you can set from a parent or on the card itself:
--dui-card-spacing, --dui-card-radius, --dui-card-bg, --dui-card-fg, --dui-card-border
-->
<style scoped>
.card {
/* Inherited by the card's parts (header, content, footer) for their padding. */
--card-spacing: var(--dui-card-spacing, var(--dui-space-6));
--card-title-size: var(--dui-text-base);
display: flex;
flex-direction: column;
gap: var(--card-spacing);
padding-block: var(--card-spacing);
overflow: hidden;
border-radius: var(--dui-card-radius, var(--dui-radius-xl));
background: var(--dui-card-bg, var(--dui-color-card));
color: var(--dui-card-fg, var(--dui-color-card-foreground));
font-size: var(--dui-text-sm);
box-shadow:
0 0 0 1px
var(--dui-card-border, color-mix(in oklch, var(--dui-color-foreground) 10%, transparent)),
var(--dui-shadow-xs);
}
.card[data-size='sm'] {
--card-spacing: var(--dui-card-spacing, var(--dui-space-4));
--card-title-size: var(--dui-text-sm);
}
</style>
<template>
<div class="action"><slot /></div>
</template>
<style scoped>
.action {
grid-column: 2;
grid-row: 1 / span 2;
align-self: start;
justify-self: end;
margin-inline-start: var(--dui-space-4);
}
</style>
<template>
<div class="content"><slot /></div>
</template>
<style scoped>
.content {
padding-inline: var(--card-spacing);
}
</style>
<template>
<p class="description"><slot /></p>
</template>
<style scoped>
.description {
grid-column: 1;
margin: 0;
color: var(--dui-color-muted-foreground);
font-size: var(--dui-text-sm);
}
</style>
<template>
<div class="footer"><slot /></div>
</template>
<style scoped>
.footer {
display: flex;
align-items: center;
gap: var(--dui-space-2);
padding-inline: var(--card-spacing);
}
</style>
<template>
<div class="header"><slot /></div>
</template>
<style scoped>
.header {
/* Two columns so Card.Action can sit top-right beside the title and description. */
display: grid;
grid-template-columns: 1fr auto;
align-items: start;
row-gap: var(--dui-space-1);
padding-inline: var(--card-spacing);
}
</style>
<template>
<div class="title"><slot /></div>
</template>
<style scoped>
.title {
grid-column: 1;
font-size: var(--card-title-size);
line-height: 1.5;
font-weight: var(--dui-weight-medium);
}
</style>
export { default as Root } from './Card.vue';
export { default as Header } from './CardHeader.vue';
export { default as Title } from './CardTitle.vue';
export { default as Description } from './CardDescription.vue';
export { default as Action } from './CardAction.vue';
export { default as Content } from './CardContent.vue';
export { default as Footer } from './CardFooter.vue';
Customizing
Set any of these on the component or on a parent element. See Customizing for how they work.
| Custom property | Default |
|---|---|
--dui-card-spacing | var(--dui-space-6) |
--dui-card-radius | var(--dui-radius-xl) |
--dui-card-bg | var(--dui-color-card) |
--dui-card-fg | var(--dui-color-card-foreground) |
--dui-card-border | color-mix(in oklch, var(--dui-color-foreground) 10%, transparent) |