Presets

Blocks

Get PRO

Need premium blocks and templates? Upgrade to PRO and get access.

Upgrade
JoinLogin
Presets
Monochrome
Overview
  • Introduction
  • Components
  • Installation
Components
  • Accordion
  • Alert
  • Alert Dialog
  • Aspect Ratio
  • Avatar
  • Badge
  • Breadcrumb
  • Button
  • Button Group
  • CalendarNEW
  • Card
  • CarouselNEW
  • Checkbox
  • Collapsible
  • Dialog
  • Dropdown Menu
  • Empty
  • Field
  • Input
  • Input Group
  • Item
  • Kbd
  • Label
  • Native Select
  • Scroll Area
  • SelectNEW
  • Separator
  • SwitchNEW
  • Table
  • Tabs
  • Textarea
  • TooltipNEW

Card

PreviousNext

Displays a card with header, content, and footer.

1<script lang="ts">
2import { Button } from "@/components/ui/button"
3import {
4  Card,

Installation

pnpm dlx sprawlify@latest add card
npx sprawlify@latest add card
yarn sprawlify@latest add card
bunx --bun sprawlify@latest add card

Install the following dependencies:

pnpm add @sprawlify/primitives @sprawlify/svelte
npm install @sprawlify/primitives @sprawlify/svelte
yarn add @sprawlify/primitives @sprawlify/svelte
bun add @sprawlify/primitives @sprawlify/svelte

Add the following files to your project:

card/card-action.svelte
1<script lang="ts">
2import { cn } from "@/lib/utils"
3import { Sprawlify, type PolymorphicProps } from "@sprawlify/svelte"
4import type { HTMLAttributes } from "svelte/elements"
5
6interface Props extends HTMLAttributes<HTMLDivElement>, PolymorphicProps<"div"> {}
7
8let { class: className, children, ...rest }: Props = $props()
9</script>
10
11<Sprawlify
12  as="div"
13  data-scope="card"
14  data-part="action"
15  data-slot="card-action"
16  class={cn(
17    "col-start-2 row-span-2 row-start-1 self-start justify-self-end",
18    className
19  )}
20  {...rest}
21>
22  {@render children?.()}
23</Sprawlify>
card/card-content.svelte
1<script lang="ts">
2import { cn } from "@/lib/utils"
3import { Sprawlify, type PolymorphicProps } from "@sprawlify/svelte"
4import type { HTMLAttributes } from "svelte/elements"
5
6interface Props extends HTMLAttributes<HTMLDivElement>, PolymorphicProps<"div"> {}
7
8let { class: className, children, ...rest }: Props = $props()
9</script>
10
11<Sprawlify
12  as="div"
13  data-scope="card"
14  data-part="content"
15  data-slot="card-content"
16  class={cn("px-4 group-data-[size=sm]/card:px-3", className)}
17  {...rest}
18>
19  {@render children?.()}
20</Sprawlify>
card/card-description.svelte
1<script lang="ts">
2import { cn } from "@/lib/utils"
3import { Sprawlify, type PolymorphicProps } from "@sprawlify/svelte"
4import type { HTMLAttributes } from "svelte/elements"
5
6interface Props extends HTMLAttributes<HTMLDivElement>, PolymorphicProps<"div"> {}
7
8let { class: className, children, ...rest }: Props = $props()
9</script>
10
11<Sprawlify
12  as="div"
13  data-scope="card"
14  data-part="description"
15  data-slot="card-description"
16  class={cn("text-muted-foreground text-sm", className)}
17  {...rest}
18>
19  {@render children?.()}
20</Sprawlify>
card/card-footer.svelte
1<script lang="ts">
2import { cn } from "@/lib/utils"
3import { Sprawlify, type PolymorphicProps } from "@sprawlify/svelte"
4import type { HTMLAttributes } from "svelte/elements"
5
6interface Props extends HTMLAttributes<HTMLDivElement>, PolymorphicProps<"div"> {}
7
8let { class: className, children, ...rest }: Props = $props()
9</script>
10
11<Sprawlify
12  as="div"
13  data-scope="card"
14  data-part="footer"
15  data-slot="card-footer"
16  class={cn("bg-muted/50 rounded-b-xl border-t p-4 group-data-[size=sm]/card:p-3 flex items-center", className)}
17  {...rest}
18>
19  {@render children?.()}
20</Sprawlify>
card/card-header.svelte
1<script lang="ts">
2import { cn } from "@/lib/utils"
3import { Sprawlify, type PolymorphicProps } from "@sprawlify/svelte"
4import type { HTMLAttributes } from "svelte/elements"
5
6interface Props extends HTMLAttributes<HTMLDivElement>, PolymorphicProps<"div"> {}
7
8let { class: className, children, ...rest }: Props = $props()
9</script>
10
11<Sprawlify
12  as="div"
13  data-scope="card"
14  data-part="header"
15  data-slot="card-header"
16  class={cn(
17    "gap-1 rounded-t-xl px-4 group-data-[size=sm]/card:px-3 [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3 group/card-header @container/card-header grid auto-rows-min items-start has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto]",
18    className
19  )}
20  {...rest}
21>
22  {@render children?.()}
23</Sprawlify>
card/card-title.svelte
1<script lang="ts">
2import { cn } from "@/lib/utils"
3import { Sprawlify, type PolymorphicProps } from "@sprawlify/svelte"
4import type { HTMLAttributes } from "svelte/elements"
5
6interface Props extends HTMLAttributes<HTMLDivElement>, PolymorphicProps<"div"> {}
7
8let { class: className, children, ...rest }: Props = $props()
9</script>
10
11<Sprawlify
12  as="div"
13  data-scope="card"
14  data-part="title"
15  data-slot="card-title"
16  class={cn("text-base leading-snug font-medium group-data-[size=sm]/card:text-sm", className)}
17  {...rest}
18>
19  {@render children?.()}
20</Sprawlify>
card/card.svelte
1<script lang="ts">
2import { cn } from "@/lib/utils"
3import { Sprawlify, type PolymorphicProps } from "@sprawlify/svelte"
4import type { HTMLAttributes } from "svelte/elements"
5
6interface Props extends HTMLAttributes<HTMLDivElement>, PolymorphicProps<"div"> {
7  size?: "default" | "sm"
8}
9
10let { class: className, size = "default", children, ...rest }: Props = $props()
11</script>
12
13<Sprawlify
14  as="div"
15  data-scope="card"
16  data-part="root"
17  data-slot="card"
18  data-size={size}
19  class={cn("ring-foreground/10 bg-card text-card-foreground gap-4 overflow-hidden rounded-xl py-4 text-sm ring-1 has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-3 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl group/card flex flex-col", className)}
20  {...rest}
21>
22  {@render children?.()}
23</Sprawlify>
card/index.ts
1export { default as Card } from "./card.svelte";2export { default as CardHeader } from "./card-header.svelte";3export { default as CardTitle } from "./card-title.svelte";4export { default as CardDescription } from "./card-description.svelte";5export { default as CardAction } from "./card-action.svelte";6export { default as CardContent } from "./card-content.svelte";7export { default as CardFooter } from "./card-footer.svelte";8

Update the import paths to match your project setup.

Usage

1import {
2  Card,
3  CardHeader,
4  CardFooter,
5  CardTitle,
6  CardAction,
7  CardDescription,
8  CardContent
9} from "@/components/ui/card"
1<Card>
2  <CardHeader>
3    <CardTitle>Card Title</CardTitle>
4    <CardDescription>Card Description</CardDescription>
5    <CardAction>Card Action</CardAction>
6  </CardHeader>
7  <CardContent>
8    <p>Card Content</p>
9  </CardContent>
10  <CardFooter>
11    <p>Card Footer</p>
12  </CardFooter>
13</Card>

Examples

Image

Add an image before the card header to create a card with an image.

1<script lang="ts">
2import { Badge } from "@/components/ui/badge"
3import { Button } from "@/components/ui/button"
4import {

Size

Use the size="sm" prop to set the size of the card to small. The small size variant uses smaller spacing.

1<script lang="ts">
2import { Button } from "@/components/ui/button"
3import {
4  Card,

On This Page

InstallationUsageExamplesImageSize

Get PRO

Need premium blocks and templates? Upgrade to PRO and get access.