Docs
Card
Card
Displays a card with header, content, and footer.
Loading...
<script lang="ts">
import { Button } from "$lib/components/ui/button";
import * as Card from "$lib/components/ui/card";
import * as Select from "$lib/components/ui/select";
import { Input } from "$lib/components/ui/input";
import { Label } from "$lib/components/ui/label";
const frameworks = [
{
value: "sveltekit",
label: "SvelteKit"
},
{
value: "next",
label: "Next.js"
},
{
value: "astro",
label: "Astro"
},
{
value: "nuxt",
label: "Nuxt.js"
}
];
</script>
<Card.Root class="w-[350px]">
<Card.Header>
<Card.Title>Create project</Card.Title>
<Card.Description>Deploy your new project in one-click.</Card.Description>
</Card.Header>
<Card.Content>
<form>
<div class="grid w-full items-center gap-4">
<div class="flex flex-col space-y-1.5">
<Label for="name">Name</Label>
<Input id="name" placeholder="Name of your project" />
</div>
<div class="flex flex-col space-y-1.5">
<Label for="framework">Framework</Label>
<Select.Root>
<Select.Trigger id="framework">
<Select.Value placeholder="Select" />
</Select.Trigger>
<Select.Content>
{#each frameworks as framework}
<Select.Item value={framework.value} label={framework.label}
>{framework.label}</Select.Item
>
{/each}
</Select.Content>
</Select.Root>
</div>
</div>
</form>
</Card.Content>
<Card.Footer class="flex justify-between">
<Button variant="outline">Cancel</Button>
<Button>Deploy</Button>
</Card.Footer>
</Card.Root>
<script lang="ts">
import { Button } from "$lib/components/ui/button";
import * as Card from "$lib/components/ui/card";
import * as Select from "$lib/components/ui/select";
import { Input } from "$lib/components/ui/input";
import { Label } from "$lib/components/ui/label";
const frameworks = [
{
value: "sveltekit",
label: "SvelteKit"
},
{
value: "next",
label: "Next.js"
},
{
value: "astro",
label: "Astro"
},
{
value: "nuxt",
label: "Nuxt.js"
}
];
</script>
<Card.Root class="w-[350px]">
<Card.Header>
<Card.Title>Create project</Card.Title>
<Card.Description>Deploy your new project in one-click.</Card.Description>
</Card.Header>
<Card.Content>
<form>
<div class="grid w-full items-center gap-4">
<div class="flex flex-col space-y-1.5">
<Label for="name">Name</Label>
<Input id="name" placeholder="Name of your project" />
</div>
<div class="flex flex-col space-y-1.5">
<Label for="framework">Framework</Label>
<Select.Root>
<Select.Trigger id="framework">
<Select.Value placeholder="Select" />
</Select.Trigger>
<Select.Content>
{#each frameworks as framework}
<Select.Item value={framework.value} label={framework.label}
>{framework.label}</Select.Item
>
{/each}
</Select.Content>
</Select.Root>
</div>
</div>
</form>
</Card.Content>
<Card.Footer class="flex justify-between">
<Button variant="outline">Cancel</Button>
<Button>Deploy</Button>
</Card.Footer>
</Card.Root>
Installation
npx shadcn-svelte@latest add card
Usage
<script lang="ts">
import * as Card from "$lib/components/ui/card";
</script>
<Card.Root>
<Card.Header>
<Card.Title>Card Title</Card.Title>
<Card.Description>Card Description</Card.Description>
</Card.Header>
<Card.Content>
<p>Card Content</p>
</Card.Content>
<Card.Footer>
<p>Card Footer</p>
</Card.Footer>
</Card.Root>
Modify the heading level
By default, the <Card.Title>
component renders an <h3>
element. You can change this by passing a tag
prop to the component.
For example:
<Card.Title tag="h2">This will render an H2</Card.Title>
<Card.Title tag="h5">This will render an H5</Card.Title>
<Card.Title tag="p">This will render a P tag</Card.Title>
Examples
Loading...
<script lang="ts">
import { Bell, Check } from "radix-icons-svelte";
import { Button } from "$lib/components/ui/button";
import * as Card from "$lib/components/ui/card";
import { Switch } from "$lib/components/ui/switch";
const notifications = [
{
title: "Your call has been confirmed.",
description: "1 hour ago"
},
{
title: "You have a new message!",
description: "1 hour ago"
},
{
title: "Your subscription is expiring soon!",
description: "2 hours ago"
}
];
</script>
<Card.Root class="w-[380px]">
<Card.Header>
<Card.Title>Notifications</Card.Title>
<Card.Description>You have 3 unread messages.</Card.Description>
</Card.Header>
<Card.Content class="grid gap-4">
<div class="flex items-center space-x-4 rounded-md border p-4">
<Bell />
<div class="flex-1 space-y-1">
<p class="text-sm font-medium leading-none">Push Notifications</p>
<p class="text-sm text-muted-foreground">
Send notifications to device.
</p>
</div>
<Switch />
</div>
<div>
{#each notifications as notification, idx (idx)}
<div
class="mb-4 grid grid-cols-[25px_1fr] items-start pb-4 last:mb-0 last:pb-0"
>
<span class="flex h-2 w-2 translate-y-1 rounded-full bg-sky-500" />
<div class="space-y-1">
<p class="text-sm font-medium leading-none">
{notification.title}
</p>
<p class="text-sm text-muted-foreground">
{notification.description}
</p>
</div>
</div>
{/each}
</div>
</Card.Content>
<Card.Footer>
<Button class="w-full">
<Check class="mr-2 h-4 w-4" /> Mark all as read
</Button>
</Card.Footer>
</Card.Root>
<script lang="ts">
import { BellRing, Check } from "lucide-svelte";
import { Button } from "$lib/components/ui/button";
import * as Card from "$lib/components/ui/card";
import { Switch } from "$lib/components/ui/switch";
const notifications = [
{
title: "Your call has been confirmed.",
description: "1 hour ago"
},
{
title: "You have a new message!",
description: "1 hour ago"
},
{
title: "Your subscription is expiring soon!",
description: "2 hours ago"
}
];
</script>
<Card.Root class="w-[380px]">
<Card.Header>
<Card.Title>Notifications</Card.Title>
<Card.Description>You have 3 unread messages.</Card.Description>
</Card.Header>
<Card.Content class="grid gap-4">
<div class=" flex items-center space-x-4 rounded-md border p-4">
<BellRing />
<div class="flex-1 space-y-1">
<p class="text-sm font-medium leading-none">Push Notifications</p>
<p class="text-sm text-muted-foreground">
Send notifications to device.
</p>
</div>
<Switch />
</div>
<div>
{#each notifications as notification, idx (idx)}
<div
class="mb-4 grid grid-cols-[25px_1fr] items-start pb-4 last:mb-0 last:pb-0"
>
<span class="flex h-2 w-2 translate-y-1 rounded-full bg-sky-500" />
<div class="space-y-1">
<p class="text-sm font-medium leading-none">
{notification.title}
</p>
<p class="text-sm text-muted-foreground">
{notification.description}
</p>
</div>
</div>
{/each}
</div>
</Card.Content>
<Card.Footer>
<Button class="w-full">
<Check class="mr-2 h-4 w-4" /> Mark all as read
</Button>
</Card.Footer>
</Card.Root>
On This Page