A compound display surface with header, content, footer, and composable actions.
Job listing
Motion Designer
- Part-time Part-time
- Remote Remote
Release note
Compound cards refresh
Purpose
A card brings related information and actions together in one surface, with room for a title, content, and optional actions.
Parts & Composition
Typical flow: Header (CardHeader) → Content (CardContent) → Footer (CardFooter). All regions are optional.
Header
| Part | Role | Notes |
|---|---|---|
CardHeader | Row | separator bottom rule (default false) |
CardHeaderText | Stack | CardSubtitle + CardHeaderCaption |
CardMedia | Logo | Place beside CardHeaderText or standalone |
CardSubtitle / CardHeaderCaption | Lines | Primary and supporting header copy |
Body & footer
| Part | Role | Notes |
|---|---|---|
Card | article | --card-accent for usage accents |
CardTitle / CardDescription | Main copy | Title as: h2, h3 (default), h4 |
CardFooter | Row | separator top rule (default true) |
CardActions | Controls | Flexible action row for buttons or links |
Root title is the native tooltip, not the visible title.
API & Props
Card accepts size="xs", "sm", "md" (default), or "lg" for its width and region inset. Style the root through className or the data-size attribute.
| Prop / part | Purpose |
|---|---|
Card | Native article props, including className, children, and labeling attributes. |
CardHeader.separator | Adds a divider below the header. Default false. |
CardTitle.as | Heading level h2 / h3 / h4. Default h3. |
CardFooter.separator | Adds a divider above the footer. Default true. |
Other Card parts | Accept props for their native element, including className and children. |
State & forms
Persistence and save actions belong in your app. The default example shows a static save control—wire up state or routing as needed.
Theming, Layout & Responsiveness
--card-accent tints accent markup you add in usage (for example the top cap in the default demo). Padding and shadow via className.
Header, content, and footer share the same horizontal inset column. Header and footer own their vertical padding inside the band (py on those parts); content stays py-0 so title and tags are not double-padded. No extra root gap or margins between regions—the header’s bottom padding is intentional inset, not a floating gutter. For equal-height grids, add className="mt-auto" on CardFooter. Phones: save actions icon-first; footer actions full width.
Motion & Accessibility
Repeatable cards: aria-label on the card or on primary actions. Name icon-only save controls with aria-label. Put router links or dialogs in CardFooter or CardActions.
Guidance for Coding Agents
Install Card using the command on the Install tab. Read this Info page before implementing.
Compose the Card regions you need and omit the others. Choose the title heading level for the surrounding document. Keep actions in the header or footer and use the shared surface spacing before adding custom padding or dividers.
Put primary actions or links in CardActions or CardFooter, and use CardHeader / CardFooter for consistent surfaceHeaderRadius / surfaceFooterRadius insets. Keep the card as a content surface when it contains interactive controls.
Start from the closest Preview → Usage example and use this page’s API table for component parts and options.
Registry
Server-compatible display compound. Depends on Separator in the footer.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/cardimport { cva } from 'class-variance-authority';
import type { ComponentProps } from 'react';
import { Separator } from '@/components/devvarena-ui/separator';
import {
type StandardControlSize,
surfaceBodyPadding,
surfaceFooterRadius,
surfaceHeaderRadius,
surfacePadding,
surfaceRegionInset,
} from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
const cardSizes = cva(null, {
variants: {
size: {
xs: 'max-w-xs [--surface-padding:1.3rem]',
sm: 'max-w-sm [--surface-padding:1.35rem]',
md: 'max-w-sm',
lg: 'max-w-lg [--surface-padding:1.75rem]',
},
},
});
type CardProps = ComponentProps<'article'> & { size?: StandardControlSize };
/** Compound display surface with elevation and composable regions. */
function Card({ className, children, size = 'md', ...props }: CardProps) {
return (
<article
{...props}
data-slot="card"
data-size={size}
className={cn(
'group/card relative isolate flex w-full min-w-0 flex-col',
surfacePadding,
cardSizes({ size }),
'rounded-lg border border-border bg-card text-card-foreground shadow-sm transition-[box-shadow,border-color] duration-200 hover:shadow-md motion-reduce:transition-none',
className,
)}
>
{children}
</article>
);
}
/** Header row for media, text, and trailing controls. */
function CardHeader({
separator = false,
className,
children,
...props
}: ComponentProps<'header'> & { separator?: boolean }) {
return (
<header
{...props}
data-slot="card-header"
className={cn(
surfaceHeaderRadius,
'[&.sticky]:top-0',
surfaceRegionInset,
'flex items-start justify-between gap-3 relative',
className,
)}
>
{separator ? <Separator className="absolute inset-x-0 bottom-0 w-auto" /> : null}
{children}
</header>
);
}
/** Vertical primary / supporting lines in the header (e.g. company + posted time). */
function CardHeaderText({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="card-header-text"
className={cn('flex min-w-0 flex-1 flex-col', className)}
/>
);
}
function CardHeaderCaption({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="card-header-caption"
className={cn('mt-0.5 text-xs leading-relaxed text-foreground/65', className)}
/>
);
}
function CardMedia({ className, ...props }: ComponentProps<'div'>) {
return (
<div
aria-hidden="true"
{...props}
data-slot="card-media"
className={cn(
'relative isolate flex size-12 shrink-0 items-center justify-center rounded-lg bg-foreground text-xl text-background shadow-[inset_0_1px_0_rgb(255_255_255/0.35),inset_0_-1px_0_rgb(0_0_0/0.2),0_2px_4px_rgb(0_0_0/0.12)] before:pointer-events-none before:absolute before:inset-0 before:rounded-[inherit] before:bg-[linear-gradient(135deg,rgb(255_255_255/0.22),transparent_42%,rgb(0_0_0/0.08))] after:pointer-events-none after:absolute after:inset-x-2 after:top-0 after:h-px after:bg-[linear-gradient(90deg,transparent,rgb(255_255_255/0.65),transparent)] dark:before:opacity-40 dark:after:opacity-40 [&>svg]:relative [&>svg]:size-6 [&>img]:relative [&>img]:size-8 [&>img]:rounded-lg [&>img]:object-contain',
className,
)}
/>
);
}
function CardSubtitle({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="card-subtitle"
className={cn('block max-w-full break-words text-sm font-semibold tracking-tight', className)}
/>
);
}
function CardContent({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="card-content"
className={cn(surfaceRegionInset, 'min-w-0', surfaceBodyPadding, className)}
/>
);
}
function CardTitle({
as: Heading = 'h3',
className,
...props
}: ComponentProps<'h3'> & { as?: 'h2' | 'h3' | 'h4' }) {
return (
<Heading
{...props}
data-slot="card-title"
className={cn(
'm-0 max-w-[22ch] break-words text-xl font-semibold leading-[1.25] tracking-tight text-balance',
className,
)}
/>
);
}
function CardDescription({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="card-description"
className={cn('mt-2 text-sm leading-relaxed text-muted-foreground', className)}
/>
);
}
/** Footer row for metadata and actions. */
function CardFooter({
separator = true,
className,
children,
...props
}: ComponentProps<'footer'> & { separator?: boolean }) {
return (
<footer
{...props}
data-slot="card-footer"
className={cn(
surfaceFooterRadius,
'relative [&.sticky]:bottom-0 mt-0',
surfaceRegionInset,
'flex flex-col items-stretch justify-between gap-4 md:flex-row md:flex-wrap md:items-center md:gap-3',
className,
)}
>
{separator ? <Separator className="absolute inset-x-0 top-0 w-auto" /> : null}
{children}
</footer>
);
}
function CardActions({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="card-actions"
className={cn('w-full flex-1 min-w-0 flex-wrap items-stretch gap-2 flex', className)}
/>
);
}
export {
Card,
CardActions,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardHeaderCaption,
CardHeaderText,
CardMedia,
CardSubtitle,
CardTitle,
};
import { Separator as SDKSeparator } from '@ui-sdk/react/separator';
import type { ComponentProps } from 'react';
import { partClass } from '@/lib/devvarena-ui';
type SeparatorProps = ComponentProps<typeof SDKSeparator> & { variant?: 'fade' | 'solid' };
/** Theme-derived fading rule built on `@ui-sdk/react/separator`. */
function Separator({
orientation = 'horizontal',
decorative = true,
variant = 'fade',
className,
...props
}: SeparatorProps) {
return (
<SDKSeparator
{...props}
orientation={orientation}
decorative={decorative}
data-variant={variant}
className={partClass(
'pointer-events-none shrink-0',
orientation === 'horizontal' ? 'h-px w-full' : 'w-px self-stretch',
variant === 'solid'
? 'bg-[var(--separator-color,var(--border))]'
: orientation === 'horizontal'
? 'bg-[linear-gradient(to_right,transparent,var(--separator-color,var(--border))_18%,var(--separator-color,var(--border))_82%,transparent)]'
: 'bg-[linear-gradient(to_bottom,transparent,var(--separator-color,var(--border))_18%,var(--separator-color,var(--border))_82%,transparent)]',
className,
)}
/>
);
}
export type { SeparatorProps };
export { Separator };
import { cn } from '@/lib/utils';
type ClassValue = string | false | null | undefined;
type PartClassValue<State> = ClassValue | ((state: State) => ClassValue);
/** Composes static class names and UI-SDK state class functions into a single `className` prop. */
export function partClass<State>(...parts: PartClassValue<State>[]) {
if (parts.some((part) => typeof part === 'function')) {
return (state: State) =>
cn(...parts.map((part) => (typeof part === 'function' ? part(state) : part)));
}
return cn(...(parts as ClassValue[]));
}
export const surfacePadding = 'p-1 [--surface-padding:1.5rem] [--concentric-inset:0.25rem]';
export const surfaceRegionInset = 'p-[calc(var(--surface-padding,1rem)-0.5rem)]';
export const surfaceHeaderRadius = 'rounded-t-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
export const surfaceFooterRadius = 'rounded-b-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
/** Concentric inner radius (`outer - inset`); set `[--concentric-inset:0.125rem]` on `p-0.5` rails (defaults to `0.25rem` for `p-1`). */
export const concentricRadius =
'rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))]';
export const surfaceBodyPadding =
'py-[max(0px,calc(var(--surface-padding,1rem)-1rem))] has-[>[data-slot=list]:not([data-variant=plain])]:p-0 has-[>[data-slot=list-items-container]]:p-0';
export type StandardControlSize = 'xs' | 'sm' | 'md' | 'lg';
/** Standard control heights (`28px / 32px / 40px / 48px`) for buttons, inputs, selects, tabs, and sliders. */
export const controlHeights = {
xs: 'h-7',
sm: 'h-8',
md: 'h-10',
lg: 'h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard minimum control heights (`28px / 32px / 40px / 48px`) for expandable controls and menu items. */
export const controlMinHeights = {
xs: 'min-h-7',
sm: 'min-h-8',
md: 'min-h-10',
lg: 'min-h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard control text sizes (`xs / xs / sm / base`) paired with `StandardControlSize`. */
export const controlTextSizes = {
xs: 'text-xs',
sm: 'text-xs',
md: 'text-sm',
lg: 'text-base',
} as const satisfies Record<StandardControlSize, string>;
/** Compact control heights (`1.25rem / 1.3rem / 1.625rem / 1.75rem`), one step smaller than standard, for switches and compact controls. */
export const compactControlHeights = {
xs: 'h-[1.3rem]',
sm: 'h-[1.4rem]',
md: 'h-[1.5rem]',
lg: 'h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Compact minimum control heights (`1rem / 1.25rem / 1.5rem / 1.75rem`) for badges and tooltips. */
export const compactControlMinHeights = {
xs: 'min-h-[1.3rem]',
sm: 'min-h-[1.4rem]',
md: 'min-h-[1.5rem]',
lg: 'min-h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Universal keyboard focus + invalid ring/border styles shared across controls. */
export const focusRing =
'touch-manipulation outline-none focus-visible:border-ring/30 transition-ring focus-visible:ring-3 focus-visible:ring-ring/15 focus-visible:brightness-[0.97] dark:focus-visible:brightness-[1.15] has-[:focus-visible]:border-ring/30 has-[:focus-visible]:ring-3 has-[:focus-visible]:ring-ring/15 has-[:focus-visible]:brightness-[0.97] dark:has-[:focus-visible]:brightness-[1.15] data-active:border-ring/30 data-active:ring-3 data-active:ring-ring/15 data-active:brightness-[0.97] dark:data-active:brightness-[1.15] data-open:border-ring/30 data-open:ring-3 data-open:ring-ring/15 data-open:brightness-[0.97] dark:data-open:brightness-[1.15] data-disabled:cursor-not-allowed data-disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/25 data-invalid:border-destructive data-invalid:ring-3 data-invalid:ring-destructive/25 has-[[data-invalid]]:border-destructive has-[[data-invalid]]:ring-3 has-[[data-invalid]]:ring-destructive/25 group-aria-invalid/control:border-destructive group-aria-invalid/control:ring-3 group-aria-invalid/control:ring-destructive/25 group-data-invalid/control:border-destructive group-data-invalid/control:ring-3 group-data-invalid/control:ring-destructive/25 group-has-[input[aria-invalid=true]]/control:border-destructive group-has-[input[aria-invalid=true]]/control:ring-3 group-has-[input[aria-invalid=true]]/control:ring-destructive/25 hover:brightness-[0.97] dark:hover:brightness-[1.15]';
/** Shared sliding highlight indicator base (pointer-safe, concentric inner radius inside rounded-lg containers, 200ms transition). */
export const slidingHighlight =
'pointer-events-none -z-10 rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))] bg-primary/10 [clip-path:inset(0px_round_max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem))))] transition-[transform,width,height,opacity] duration-200 ease-out motion-reduce:transition-none';
export const textFieldSurfaces = {
filled: 'border-input bg-card text-card-foreground',
outline: 'border-input bg-transparent text-foreground dark:bg-transparent',
ghost: 'border-transparent bg-muted text-foreground shadow-none',
underline:
'rounded-none border-0 border-b-2 border-input bg-transparent px-0 text-foreground shadow-none focus-visible:border-ring focus-visible:ring-0 aria-invalid:ring-0 data-invalid:ring-0 dark:bg-transparent',
} as const;
export const textFieldUnderlineMotion =
'border-transparent! bg-origin-border bg-bottom bg-no-repeat [--underline-color:var(--primary)] [background-image:linear-gradient(var(--underline-color),var(--underline-color)),linear-gradient(var(--input),var(--input))] [background-size:0%_2px,100%_2px] focus:[background-size:100%_2px,100%_2px] aria-invalid:[--underline-color:var(--destructive)] data-invalid:[--underline-color:var(--destructive)] transition-[border-color,background-color,box-shadow,filter,background-size] duration-200 motion-reduce:transition-none';
/** Generic balanced icon & floating-label layout tokens shared across all text-field sizes. */
export const textFieldLayout = {
icon: 'size-4',
iconStart: 'start-3',
iconEnd: 'end-3',
padStart: 'ps-9',
padEnd: 'pe-9',
underlinePadStart: 'ps-7',
underlinePadEnd: 'pe-7',
floatingStart: 'start-2.5',
floatingWithIcon: 'start-8',
floatingUnderlineIcon: 'start-6',
} as const;
export const textFieldLabelSegmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
/** Clamps per-grapheme wave delay (ms) so total staggering stays within 300ms. */
export function clampWaveDelay(waveDelay: number, count: number): number {
return Math.max(
0,
Math.min(Number.isFinite(waveDelay) ? waveDelay : 24, 80, 300 / Math.max(1, count - 1)),
);
}
/** Shared scale/color transition for floating labels inside a `group/field` wrapper. */
export const textFieldLabelMotion =
'inline-block origin-left backdrop-blur-xs transition-[scale,color] duration-200 ease-out group-has-[input:focus]/field:scale-85 group-has-[input:not(:placeholder-shown)]/field:scale-85 rtl:origin-right motion-reduce:transition-none';
/** Resolves start/end padding for a text field when a leading or trailing icon is present. */
export function getTextFieldIconPadding(iconPosition: 'start' | 'end', underline: boolean): string {
if (iconPosition === 'start') {
return underline ? textFieldLayout.underlinePadStart : textFieldLayout.padStart;
}
return underline ? textFieldLayout.underlinePadEnd : textFieldLayout.padEnd;
}
/** Shared per-grapheme ripple transition for wave labels inside a `group/field` wrapper. */
export const textFieldWaveMotion =
'inline-block origin-left backdrop-blur-xs transition-[translate,scale,color] duration-200 ease-out group-has-[input:focus]/field:-translate-y-5 group-has-[input:focus]/field:scale-85 group-has-[input:focus]/field:text-primary group-has-[input:not(:placeholder-shown)]/field:-translate-y-5 group-has-[input:not(:placeholder-shown)]/field:scale-85 group-has-[input[aria-invalid=true]]/field:text-destructive rtl:origin-right motion-reduce:transition-none';