Container Card
shadcn-htmx/container-cardFreeComponent
A self-adapting card that restyles based on its own inline width, not the viewport. The same markup stacks media above text in a narrow column or sidebar and lays them side-by-side in a wide column or grid cell — built on CSS container queries (container-type: inline-size + @container). Pure CSS, zero JavaScript.
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/container-card.jsonSource
1/** @jsxImportSource hono/jsx */2import type { Child, PropsWithChildren } from "hono/jsx"3import { cn, type ClassValue } from "@/registry/lib/cn"45// Container Card — shadcn-htmx, htmx v4 + Tailwind v4.6//7// A self-adapting card that restyles based on its OWN inline width rather than8// the viewport. The same markup renders stacked (media above text) when it sits9// in a narrow column or sidebar, and side-by-side (media beside text) when it10// has room — so one component drops into a sidebar, a wide content column, or a11// grid cell with no per-call breakpoints. Pure CSS; zero JavaScript.12//13// Built on (read before editing):14// - CSS `container-type: inline-size` — establishes the card as a size query15// container so its descendants can be styled against the card's own inline16// width (computed in isolation, with inline-size containment to avoid query17// loops). We name the container so the threshold variant targets THIS card18// and not some ancestor container.19// repos/mdn/files/en-us/web/css/reference/properties/container-type/index.md20// - The web.dev "Container query card" pattern — base styles are single21// column / centred; an `@container (min-width: …)` rule flips to a22// two-column grid and reveals the description at wider container sizes.23// repos/web.dev/src/site/content/en/patterns/layout/container-query-card/index.md24// repos/web.dev/src/site/content/en/patterns/layout/container-query-card/assets/style.css25//26// shadcn/ui's Card is a static container with no self-adapting behaviour, so27// there is no upstream class string to mirror 1:1 — we keep the same visual28// shell (rounded border, bg-card, shadow) as registry/ui/card.tsx and add the29// container-query layout.30// Card shell mirrored from: registry/ui/card.tsx31//32// Tailwind v4 container queries (verified against the engine):33// - `@container/container-card` → container-type: inline-size + container-name34// (repos/tailwindcss/packages/tailwindcss/src/utilities.ts: the `@container`35// functional utility emits `container-type` and, with a modifier, the36// `container-name`).37// - `@min-[28rem]/container-card:<util>` → wraps the utility in38// `@container container-card (min-width: 28rem)` so it only fires when THIS39// named card is at least the threshold wide40// (repos/tailwindcss/packages/tailwindcss/src/variants.ts: the `@container`41// variant supports an optional name then the size query).42// … 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 |
