Pill Tag Button
Filter chips for React: selectable pill tags with count badges and a check that slides in on a spring.
- Buttons
- Real estate
- React only · 0 deps
- 1 file
Install. One command, or copy the file.
$
npx shadcn@latest add https://freedesignmd.com/r/pill-tag-button.json- Byte-identical to the preview
- No Tailwind or config needed
- SSR-safe · keyboard accessible
- Respects reduced motion & transparency
components/buttons/pill-tag-button.tsx
1/**2 * PillTagButton, selectable filter chips with count badges and an animated3 * check that slides in when a chip is selected.4 *5 * Props: options[] ({ id, label, count?, icon?, disabled? }), value (string[]),6 * onChange(next), multiple (default true), size ("sm" | "md"), tone7 * ("neutral" | "accent"), aria-label, theme. Also exports <PillTag/> for a8 * single chip (selected, onToggle).9 *10 * Browser support: all evergreen browsers.11 * Accessibility: each chip is a <button aria-pressed> inside role="group"12 * (multiple) or a role="radiogroup" of role="radio" chips (single). Counts are13 * read as part of the name ("Condos, 64"). Visible focus, 44px-wide touch14 * target on md via padding. Reduced motion: check appears instantly.15 */16import { useState } from "react";17import type { ReactNode } from "react";18 19export interface PillOption {20 id: string;21 label: string;22 count?: number;23 icon?: ReactNode;24 disabled?: boolean;25}26 27export interface PillTagProps {28 label: string;29 count?: number;30 icon?: ReactNode;31 selected?: boolean;32 disabled?: boolean;33 onToggle?: () => void;34 size?: "sm" | "md";35 tone?: "neutral" | "accent";36 radio?: boolean;37}38 39export function PillTag({ label, count, icon, selected, disabled, onToggle, size = "md", tone = "neutral", radio }: PillTagProps) {40 return (41 <button42 type="button"43 className="fd-pill"44 data-size={size}45 data-tone={tone}46 data-selected={selected || undefined}47 disabled={disabled}48 onClick={onToggle}49 {...(radio ? { role: "radio", "aria-checked": !!selected } : { "aria-pressed": !!selected })}50 >51 <span className="fd-pill-check" aria-hidden="true">52 <svg aria-hidden="true" focusable="false" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5" /></svg>53 </span>54 {icon && <span className="fd-pill-ic">{icon}</span>}55 <span className="fd-pill-label">{label}</span>56 {count !== undefined && <span className="fd-pill-count">{count}</span>}57 </button>58 );59}60 61export interface PillTagButtonProps {62 options: PillOption[];63 value: string[];64 onChange: (next: string[]) => void;65 multiple?: boolean;66 size?: "sm" | "md";67 tone?: "neutral" | "accent";68 theme?: "light" | "dark";69 className?: string;70 "aria-label"?: string;71}72 73export function PillTagButton({ options, value, onChange, multiple = true, size = "md", tone = "neutral", theme, className, "aria-label": label }: PillTagButtonProps) {74 const toggle = (id: string) => {75 if (multiple) onChange(value.includes(id) ? value.filter((v) => v !== id) : [...value, id]);76 else onChange(value.includes(id) ? [] : [id]);77 };78 return (79 <div className={`fd-pill-group${className ? " " + className : ""}`} role={multiple ? "group" : "radiogroup"} aria-label={label} data-fd-theme={theme}>80 <style>{css}</style>81 {options.map((o) => (82 <PillTag key={o.id} label={o.label} count={o.count} icon={o.icon} disabled={o.disabled} size={size} tone={tone} radio={!multiple} selected={value.includes(o.id)} onToggle={() => toggle(o.id)} />83 ))}84 </div>85 );86}87 88const css = `89:where(.fd-pill-group,.fd-pill-group *){box-sizing:border-box;margin:0;padding:0;font:inherit;letter-spacing:inherit;color:inherit;text-decoration:none;list-style:none}90:where(.fd-pill-group,.fd-pill-group *)::before,:where(.fd-pill-group,.fd-pill-group *)::after{box-sizing:border-box}91:where(.fd-pill-group svg){display:block;flex-shrink:0}92:where(.fd-pill-group button){appearance:none;-webkit-appearance:none;background:none;border:0;border-radius:0}93.fd-pill-group{94 --fd-ease-out:cubic-bezier(.22,1,.36,1);--fd-ease-in-out:cubic-bezier(.65,0,.35,1);--fd-spring:cubic-bezier(.34,1.56,.64,1);--fd-dur-1:120ms;--fd-dur-2:240ms;--fd-dur-3:420ms;95 --p-bg:#fff;--p-fg:#0B0B0F;--p-mut:#6B6B76;--p-line:rgba(11,11,15,.12);--p-hover:#F7F7F9;--p-count:rgba(11,11,15,.07);96 --p-on-bg:#0B0B0F;--p-on-fg:#fff;--p-on-count:rgba(255,255,255,.2);--p-ring:rgba(0,122,255,.7);97 display:flex;flex-wrap:wrap;gap:8px;98 font:500 14px/1 ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif;letter-spacing:-.005em;color:var(--p-fg);99}100[data-fd-theme="dark"] .fd-pill-group,.fd-pill-group[data-fd-theme="dark"]{--p-bg:#16161B;--p-fg:#F5F5F7;--p-mut:#9A9AA6;--p-line:rgba(255,255,255,.12);--p-hover:#1E1E25;--p-count:rgba(255,255,255,.09);--p-on-bg:#F5F5F7;--p-on-fg:#0B0B0F;--p-on-count:rgba(11,11,15,.14);--p-ring:rgba(10,132,255,.85)}101.fd-pill{position:relative;display:inline-flex;align-items:center;gap:0;flex-shrink:0;102 appearance:none;-webkit-appearance:none;border:0;outline:0;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent;white-space:nowrap;103 height:var(--p-h);padding:0 var(--p-px);border-radius:9999px;background:var(--p-bg);color:var(--p-fg);104 font-family:inherit;font-size:var(--p-fs);font-weight:500;line-height:1;letter-spacing:inherit;105 box-shadow:0 0 0 1px var(--p-line),0 1px 2px rgba(11,11,15,.04);106 transform:scale(1);transition:transform var(--fd-dur-3) var(--fd-spring),background-color var(--fd-dur-2) var(--fd-ease-out),color var(--fd-dur-2) var(--fd-ease-out),box-shadow var(--fd-dur-2) var(--fd-ease-out)}107.fd-pill[data-size="sm"]{--p-h:28px;--p-px:12px;--p-fs:13px;--p-chk:14px}108.fd-pill[data-size="md"]{--p-h:36px;--p-px:16px;--p-fs:14px;--p-chk:16px}109.fd-pill[data-tone="accent"]{--p-on-bg:#007AFF;--p-on-fg:#fff;--p-on-count:rgba(255,255,255,.25)}110[data-fd-theme="dark"] .fd-pill[data-tone="accent"]{--p-on-bg:#0A84FF}111@media (hover:hover){.fd-pill:hover:not(:disabled):not([data-selected]){background:var(--p-hover)}}112.fd-pill[data-selected]{background:var(--p-on-bg);color:var(--p-on-fg);box-shadow:0 0 0 1px var(--p-on-bg),0 4px 12px -6px var(--p-on-bg)}113.fd-pill:active:not(:disabled){transform:scale(.96);transition:transform var(--fd-dur-1) var(--fd-ease-out)}114.fd-pill:focus-visible{outline:2px solid var(--p-ring);outline-offset:2px}115.fd-pill:disabled{opacity:.4;cursor:not-allowed}116.fd-pill-check{display:grid;place-items:center;width:0;height:var(--p-chk);opacity:0;overflow:hidden;transform:scale(.4);117 transition:width var(--fd-dur-3) var(--fd-spring),opacity var(--fd-dur-2) var(--fd-ease-out),transform var(--fd-dur-3) var(--fd-spring),margin var(--fd-dur-3) var(--fd-spring)}118.fd-pill[data-selected] .fd-pill-check{width:var(--p-chk);margin-right:6px;opacity:1;transform:scale(1)}119.fd-pill-check path{stroke-dasharray:24;stroke-dashoffset:24;transition:stroke-dashoffset var(--fd-dur-2) var(--fd-ease-out)}120.fd-pill[data-selected] .fd-pill-check path{stroke-dashoffset:0;transition-delay:90ms}121.fd-pill-ic{display:grid;place-items:center;width:16px;height:16px;margin-right:6px;color:var(--p-mut);transition:color var(--fd-dur-2) var(--fd-ease-out)}122.fd-pill-ic svg{width:100%;height:100%}.fd-pill[data-selected] .fd-pill-ic{color:inherit}123.fd-pill-label{display:block}124.fd-pill-count{display:inline-grid;place-items:center;min-width:22px;height:20px;margin-left:8px;margin-right:-6px;padding:0 6px;border-radius:9999px;background:var(--p-count);color:var(--p-mut);font-size:12px;font-weight:600;font-variant-numeric:tabular-nums;letter-spacing:0;125 transition:background-color var(--fd-dur-2) var(--fd-ease-out),color var(--fd-dur-2) var(--fd-ease-out)}126.fd-pill[data-selected] .fd-pill-count{background:var(--p-on-count);color:inherit}127@media (prefers-reduced-motion:reduce){.fd-pill,.fd-pill:active:not(:disabled),.fd-pill-check,.fd-pill-check path{transition:none;transform:none}.fd-pill[data-selected] .fd-pill-check{transform:none}}128@media (prefers-contrast:more){.fd-pill[data-selected]{box-shadow:0 0 0 2px currentColor}}129`;130 131/* ───────────────────────────── demo ───────────────────────────── */132 133const TYPES: PillOption[] = [134 { id: "houses", label: "Houses", count: 48 },135 { id: "condos", label: "Condos", count: 64 },136 { id: "townhomes", label: "Townhomes", count: 21 },137 { id: "lofts", label: "Lofts", count: 9 },138];139 140export function Demo() {141 const [value, setValue] = useState<string[]>(["condos"]);142 return (143 <div className="fd-pilld">144 <style>{demoCss}</style>145 <div className="fd-pilld-box">146 <PillTagButton aria-label="Home type" options={TYPES} value={value} onChange={setValue} />147 </div>148 </div>149 );150}151 152const demoCss = `153.fd-pilld,.fd-pilld *,.fd-pilld *::before,.fd-pilld *::after{box-sizing:border-box}154.fd-pilld{display:flex;align-items:center;justify-content:center;min-height:100vh;width:100%;margin:0;padding:32px 20px;overflow:hidden;background:#f4f4f4;color:#1d1d1f;font:400 15px/1.4 ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif;letter-spacing:normal;-webkit-font-smoothing:antialiased}155.fd-pilld-box{display:flex;justify-content:center;max-width:560px;margin:0;padding:0}156`;More Buttons. Same file contract.
Questions about Pill Tag Button
Run npx shadcn@latest add https://freedesignmd.com/r/pill-tag-button.json, or open the page and copy the file into your project. It has zero dependencies besides React. What you copy is the exact file that renders the live demo.
Filter chips for React: selectable pill tags with count badges and a check that slides in on a spring. It is a free, MIT-licensed React buttons component from the freedesignmd library.
Yes. It is free and MIT-licensed, use, modify and ship it in personal and commercial projects without attribution.
All evergreen browsers.
Yes. It is a plain React component with its own styles, so it runs in Next.js, Vite, Remix and Lovable projects, and it needs no Tailwind setup. It has zero dependencies besides React.


