Components
Card
A surface with header, title, description, content, footer and action parts.
Server-compatible (no "use client")
import.tsx
card-basic.tsx
Edit on GitHubPurpose
Card groups related content on a surface. Its parts are context-free and composable; use only the
ones you need.
Import
import {
Card,
CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@neshel-ui/components";Usage
Preview: card-basic
Account overview
Variant “default”.
Active
Three projects, two pending invitations.
Account overview
Variant “outline”.
Active
Three projects, two pending invitations.
Account overview
Variant “muted”.
Active
Three projects, two pending invitations.
import {
Badge,
Button,
Card,
CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@neshel-ui/components";
import { Grid } from "@neshel-ui/layout";
import { Paragraph } from "@neshel-ui/typography";
const variants = ["default", "outline", "muted"] as const;
export default function CardBasic() {
return (
<Grid columns={{ base: 1, md: 3 }} space="4">
{variants.map((variant) => (
<Card key={variant} variant={variant} as="article" aria-labelledby={`card-${variant}`}>
<CardHeader>
<CardTitle id={`card-${variant}`}>Account overview</CardTitle>
<CardDescription>Variant “{variant}”.</CardDescription>
<CardAction>
<Badge variant="success">Active</Badge>
</CardAction>
</CardHeader>
<CardContent>
<Paragraph size="sm">Three projects, two pending invitations.</Paragraph>
</CardContent>
<CardFooter>
<Button size="sm">Open</Button>
<Button size="sm" variant="ghost">
Later
</Button>
</CardFooter>
</Card>
))}
</Grid>
);
}API
CardProps
| Prop | Type | Default | Description |
|---|---|---|---|
| as | E | — | — |
| asChild(required) | boolean | — | — |
| padding | CardPadding | — | — |
| ref | Ref<HTMLElement> | — | — |
| variant | CardVariant | "default" | Surface style (default "default"). |
Also accepts the props of: React DOM attributes.
CardVariant
type CardVariant = "default" | "outline" | "muted"CardPadding
type CardPadding = "sm" | "md" | "lg"CardElement
type CardElement = "div" | "section" | "article" | "aside" | "li"CardTitleProps
| Prop | Type | Default | Description |
|---|---|---|---|
| as | E | — | — |
| asChild(required) | boolean | — | — |
| ref | Ref<HTMLHeadingElement> | — | — |
Also accepts the props of: React DOM attributes.
CardTitleElement
type CardTitleElement = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "div"CardDescriptionProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLParagraphElement> | — | — |
Also accepts the props of: React DOM attributes.
CardPartProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLDivElement> | — | — |
Also accepts the props of: React DOM attributes.
| Part | Element | Notes |
|---|---|---|
Card | div (or as) | variant, padding, as, asChild |
CardHeader | div | Title, description and an optional action |
CardTitle | h3 (or as) | h1–h6, p, div; asChild |
CardDescription | p | Muted supporting text |
CardContent | div | Main content |
CardFooter | div | Actions |
CardAction | div | Placed at the end of the header |
Accessibility
- Choose
CardTitle's level (as) from the page outline. - For a card in a list of articles, use
as="article"andaria-labelledbypointing to the title. - Cards are not interactive: put buttons or links inside; never wrap a whole card in a link or button.
Common mistakes
- Making the entire card clickable with
onClick: keyboard and screen-reader users cannot discover it. - Several
CardTitles with the defaulth3breaking the heading outline.