Card
A container that groups an image and content about one thing, like a file, a project or an article.
import { Card } from '@halo-ds/react';
When to use it
A card has two slots. Media holds an image, video thumbnail or illustration, and can be hidden. Content holds anything you need below it: a title and description, an icon and an avatar, badges, or buttons. Add, remove or rearrange what is inside without detaching.
Do
- Keep cards in a set the same width and layout.
- Use images with a consistent shape, so a grid lines up.
- Put the most important text first: the title, then details.
- Make the whole card clickable when it opens one thing.
Don't
- Put buttons inside a card that is also clickable.
- Cram long text into a card; link to a full page instead.
- Mix cards with and without media in one row.
- Use a card to wrap a single line of text.
Clickable or not?
A card is either one big link, or a container with its own buttons. Never both.
- Clickable card: The whole card opens one thing, like a file or a project. Use the Hover and Focused states. Don't put buttons or links inside it.
- Card with actions: The card holds content, and its own buttons do things. Keep it in the Default state; the buttons have their own hover and focus. Use this when there is more than one action.
Props
Card props
| Prop | Type | What it does | ||
|---|---|---|---|---|
media | ReactNode | Shown on top: an image, video thumbnail or illustration. Leave it out for no media. Figma: Media slot and Show media. | ||
href | `string \ | undefined` | Makes the whole card one link. Don't put other links or buttons inside. | |
onClick | `((event: MouseEvent<HTMLElement, MouseEvent> \ | KeyboardEvent<HTMLElement>) => void) \ | undefined` | Makes the whole card one button. Don't put other links or buttons inside. |
children (required) | ReactNode | Everything below the media. Figma: Content slot. | ||
classNames | `Partial<Record<CardPart, string>> \ | undefined` | Extra class names for the parts inside the component, by part name, like { header: 'my-header' }. | |
styles | `Partial<Record<CardPart, CSSProperties>> \ | undefined` | Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }. |
It also takes the usual HTML attributes for its element.
Examples
Overview
import { Avatar, Card, Text } from '@halo-ds/react';
export default function Example() {
return (
<div style={{ width: 300 }}>
<Card media={<img src="https://images.unsplash.com/photo-1557672172-298e090bd0f1?w=600&q=80" alt="" />} href="#">
<div style={{ display: 'flex', alignItems: 'center', gap: 12, alignSelf: 'stretch' }}>
<div style={{ flex: 1 }}>
<Text weight="semibold">Brand refresh</Text>
<Text size="sm" color="secondary">Edited 5 minutes ago</Text>
</div>
<Avatar size="sm" name="Ada Obi" />
</div>
</Card>
</div>
);
}
Layouts
With an image, text only, and with badges. Cards hold any content.
import { Badge, Card, Text } from '@halo-ds/react';
export default function Demo() {
return (
<div className="demo-grid-3">
<Card media={<img src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?w=600&q=80" alt="" />}>
<Text size="lg" weight="semibold">Night sky wallpapers</Text>
<Text color="secondary">A set of 12 abstract backgrounds.</Text>
</Card>
<Card>
<Text size="lg" weight="semibold">Q4 roadmap</Text>
<Text color="secondary">Plans and goals for the next three months.</Text>
</Card>
<Card>
<div style={{ display: 'flex', gap: 8 }}>
<Badge size="sm" color="brand" variant="solid">New</Badge>
<Badge size="sm">5 min read</Badge>
</div>
<Text size="lg" weight="semibold">Designing with colour</Text>
<Text color="secondary">Build a palette that works in light and dark mode.</Text>
</Card>
</div>
);
}
Clickable
With href, the whole card is one link. Hover darkens the border, and keyboard focus shows a ring.
import { Card, Text } from '@halo-ds/react';
const images = ['photo-1557672172-298e090bd0f1', 'photo-1618005182384-a83a8bd57fbe', 'photo-1604076913837-52ab5629fba9'];
export default function Demo() {
return (
<div className="demo-grid-3">
{['Brand refresh', 'Mobile app', 'Annual report'].map((title, i) => (
<Card key={title} href="#" media={<img src={`https://images.unsplash.com/${images[i]}?w=600&q=80`} alt="" />}>
<Text weight="semibold">{title}</Text>
<Text size="sm" color="secondary">Edited today</Text>
</Card>
))}
</div>
);
}
More: https://halodesignsystem.dev/components/card