Data display
Tag
24px label with an icon, avatar, company mark or flag; stroke or gray, removable.
react-aria-componentslucide-react
Preview
BasicWith iconSarah ChenLedgerlyUnited KingdomAustin(12)
EnterpriseQ4InboundDisabled
"use client";
import { MapPin, Tag as TagIcon } from "lucide-react";
import { useState } from "react";
import { Avatar, CompanyMark } from "@/components/ui/avatar";
import { Tag } from "@/components/ui/tag";
export default function Example() {
const [tags, setTags] = useState(["Enterprise", "Q4", "Inbound"]);
return (
<div className="flex max-w-lg flex-col items-center gap-3">
<div className="flex flex-wrap justify-center gap-2">
<Tag>Basic</Tag>
<Tag leading={<TagIcon />}>With icon</Tag>
<Tag leading={<Avatar name="Sarah Chen" size="xs" />}>Sarah Chen</Tag>
<Tag leading={<CompanyMark name="Ledgerly" size="xs" color="#8a5a2b" className="!size-4 !rounded-[4px] !text-[8px]" />}>Ledgerly</Tag>
<Tag leading={<span aria-hidden>🇬🇧</span>}>United Kingdom</Tag>
<Tag leading={<MapPin />} sublabel="(12)">Austin</Tag>
</div>
<div className="flex flex-wrap justify-center gap-2">
{tags.map((t) => (
<Tag key={t} variant="gray" onRemove={() => setTags((x) => x.filter((y) => y !== t))}>{t}</Tag>
))}
<Tag isDisabled>Disabled</Tag>
</div>
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-components lucide-reactCreate a
tag.tsxfile and paste the following code into it.src/components/ui/tag.tsx"use client"; import { X } from "lucide-react"; import type { ReactNode } from "react"; import { Button as AriaButton } from "react-aria-components"; import { cx } from "@/utils/cx"; export interface TagProps { /** `stroke` white with border (default) · `gray` muted fill. */ variant?: "stroke" | "gray"; /** Leading visual: an icon, <Avatar size="xs">, <CompanyMark size="sm">, a flag… */ leading?: ReactNode; /** Muted secondary text after the label, e.g. a count. */ sublabel?: ReactNode; onRemove?: () => void; isDisabled?: boolean; className?: string; children: ReactNode; } /** Compact 24px label for people, companies, filters and categories. */ export function Tag({ variant = "stroke", leading, sublabel, onRemove, isDisabled, className, children }: TagProps) { return ( <span className={cx( "inline-flex h-6 shrink-0 items-center gap-1.5 rounded-[6px] text-sm font-medium [&>svg]:size-3.5", onRemove ? "pl-1.5 pr-1" : "px-1.5", !leading && "pl-2", variant === "stroke" ? "bg-surface text-fg ring-1 ring-inset ring-line" : "bg-muted text-fg", isDisabled && "text-fg-disabled ring-line-subtle [&_*]:opacity-60", className, )} > {leading} <span>{children}</span> {sublabel && <span className="font-normal text-fg-muted">{sublabel}</span>} {onRemove && ( <AriaButton aria-label={`Remove ${typeof children === "string" ? children : "tag"}`} onPress={onRemove} isDisabled={isDisabled} className="inline-flex size-4 items-center justify-center rounded-[4px] text-fg-muted outline-none data-hovered:bg-active data-hovered:text-fg data-focus-visible:shadow-focus" > <X className="size-3" /> </AriaButton> )} </span> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.