Card
shadcn-htmx/cardFreeComponent
Structural container — Header / Title / Description / Action / Content / Footer slots. Pure layout primitive; pair with htmx for content swaps.
Live preview
live · rendered by the registry
Rendered by shadcn-htmx on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/card.jsonSource
1/** @jsxImportSource hono/jsx */2import type { PropsWithChildren } from "hono/jsx"3import { cn, type ClassValue } from "@/registry/lib/cn"45// Card — shadcn-htmx, htmx v4 + Tailwind v4.6//7// Source of truth (1:1 class strings):8// repos/shadcn-ui/apps/v4/registry/new-york-v4/ui/card.tsx9//10// Card is structural — a rounded container with a Header / Title /11// Description / Content / Footer layout. No interactivity, no JS.12// Pair it with htmx attributes on inner elements when you need to swap13// the contents server-side.1415type CardAs = "div" | "article" | "section" | "li" | "aside"1617export function Card(18 props: PropsWithChildren<19 {20 class?: ClassValue21 id?: string22 // Semantic element. shadcn upstream hardcodes <div>; we default to23 // <div> for backwards-compat but encourage <article> for self-24 // contained content (product card, blog tile, comment) and25 // <section> for thematic groups inside a landmark.26 // See repos/mdn/files/en-us/web/html/reference/elements/article/index.md:10,65-6827 as?: CardAs28 // Pair with the id of the CardTitle inside so the rendered <article>29 // / <section> has an accessible name for AT landmark navigation.30 ariaLabelledby?: string31 ariaLabel?: string32 } & Record<string, any>33 >,34) {35 const { class: className, children, as = "div", ariaLabelledby, ariaLabel, ...rest } = props36 const Tag: any = as37 return (38 <Tag39 data-slot="card"40 class={cn(41 "flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm",42 className,43 )}44 aria-labelledby={ariaLabelledby}45 aria-label={ariaLabel}46 {...rest}47 >48 {children}49 </Tag>50 )51}5253export function CardHeader(54 props: PropsWithChildren<{ class?: ClassValue }>,55) {56 return (57 <div58 data-slot="card-header"59 class={cn(60 "@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",61 props.class,62 )}63 >64 {props.children}65 </div>66 )67}6869type CardTitleAs = "div" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6"7071export function CardTitle(72 props: PropsWithChildren<{73 class?: ClassValue74 // Render as a real heading so an `as="article"|"section"` Card gets a75 // child heading and contributes to the document outline. Default "div"76 // preserves shadcn upstream behaviour.77// … truncated
More from shadcn-htmx
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-htmx | Components | Free | no deps | |
| Active Searchactive-search | shadcn-htmx | Components | Free | no deps | |
| Alertalert | shadcn-htmx | Components | Free | no deps | |
| Alert Dialogalert-dialog | shadcn-htmx | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | shadcn-htmx | Components | Free | no deps | |
| Auto Gridauto-grid | shadcn-htmx | Components | Free | no deps | |
| Autocompleteautocomplete | shadcn-htmx | Components | Free | no deps | |
| Autosize Textareaautosize-textarea | shadcn-htmx | Components | Free | no deps |
