Tag
Small labels for things people add, choose or filter by, which they can often remove.
import { Tag } from '@halo-ds/react';
When to use it
Use tags to show values people have added or picked: topics on a post, filters that are on, emails added to an invite, or choices in a multi-select Combobox. A tag can carry an icon or an Avatar, and a ✕ to remove it. For a status people only read, like "New" or a count, use a Badge.
Do
- Keep labels short: one to three words.
- Let tags wrap onto new lines instead of cutting them off.
- Turn off Closable when people cannot change the tag.
- Offer "Clear all" when there are several removable tags.
Don't
- Use a tag for a status like Paid or New; use a Badge.
- Use colour alone to tell tags apart.
- Put long sentences in a tag.
- Hide the ✕ until hover; people on phones cannot hover.
Tag or Badge?
They look alike. A Tag is something people added or can remove; a Badge is a status they read.
- Tag: Something people added, chose or filter by. It can often be removed, and it is usually one of several.
- Badge: A status or count people only read, like New, Paid or 3. It cannot be removed.
Props
Tag props
| Prop | Type | What it does | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
color | `"neutral" \ | "purple" \ | "blue" \ | "green" \ | "orange" \ | (string & {}) \ | "yellow" \ | "red" \ | "pink" \ | undefined` | Fill and label colour. One of the preset colours, or any CSS colour (like "#7C3AED") for colours people pick themselves. Custom colours get a light tint and a darker label, and follow dark mode. Figma: Colour. |
size | `"sm" \ | "md" \ | undefined` | 24 or 28px tall. Figma: Size. | |||||||
icon | ReactNode | Icon before the label. Figma: L icon. | |||||||||
avatar | ReactNode | An Avatar before the label, for people. Use size "xs"; it fits the tag either way. Figma: Avatar. | |||||||||
onRemove | `(() => void) \ | undefined` | Shows a remove button and calls this when it is pressed. Figma: Closable. | ||||||||
removeLabel | `string \ | undefined` | Screen reader name for the remove button. Defaults to "Remove <label>". | ||||||||
disabled | `boolean \ | undefined` | |||||||||
children (required) | ReactNode | ||||||||||
classNames | `Partial<Record<TagPart, string>> \ | undefined` | Extra class names for the parts inside the component, by part name, like { header: 'my-header' }. | ||||||||
styles | `Partial<Record<TagPart, 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 { useState } from 'react';
import { Tag } from '@halo-ds/react';
export default function Example() {
const [tags, setTags] = useState(['Design', 'Research', 'Marketing', 'Finance']);
const colors = ['blue', 'green', 'orange', 'purple'] as const;
return (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
{tags.map((t, i) => (
<Tag key={t} color={colors[i % colors.length]} onRemove={() => setTags(tags.filter((x) => x !== t))}>
{t}
</Tag>
))}
</div>
);
}
Colours
The preset colours. Neutral is the default.
import { Tag } from '@halo-ds/react';
export default function Demo() {
return (
<div className="demo-row">
{(['neutral', 'blue', 'green', 'orange', 'purple', 'red'] as const).map((c) => (
<Tag key={c} color={c}>{c[0]!.toUpperCase() + c.slice(1)}</Tag>
))}
</div>
);
}
Variants
Small, with an icon, with an avatar, and disabled.
import { Avatar, Tag } from '@halo-ds/react';
import { Hash } from '@phosphor-icons/react';
export default function Demo() {
return (
<div className="demo-row">
<Tag size="sm">Small</Tag>
<Tag icon={<Hash />}>research</Tag>
<Tag avatar={<Avatar size="xs" name="Ada Obi" color="purple" />}>Ada Obi</Tag>
<Tag disabled onRemove={() => {}}>Disabled</Tag>
</div>
);
}
Your own colour
Any CSS colour works, so people can pick their own tag colours.
import { Tag } from '@halo-ds/react';
import { Hash } from '@phosphor-icons/react';
export default function Demo() {
return (
<div className="demo-row">
<Tag color="#0EA5A4" icon={<Hash />}>launch-week</Tag>
<Tag color="#D97706" icon={<Hash />}>urgent</Tag>
</div>
);
}
More: https://halodesignsystem.dev/components/tag