← Components

Selection and input · Material 3: Chips

Chip

Compact tokens: input chips you can remove, filter chips you can press, and suggestion chips that run an action.

Examples and variants

Kinds

Remove an input chip; press the filter chip.

DesignMotionTokens
Only mineAdd a cover
Example
function ChipKinds() {
  const [tags, setTags] = useState(["Design", "Motion", "Tokens"])
  const [filter, setFilter] = useState(true)
  return (
    <div className="flex flex-col items-center gap-4">
      <div className="flex flex-wrap gap-2">
        {tags.map((tag) => (
          <Chip key={tag} kind="input">
            {tag}
            <ChipRemove aria-label={`Remove ${tag}`} onClick={() => setTags((all) => all.filter((t) => t !== tag))} />
          </Chip>
        ))}
      </div>
      <div className="flex gap-2">
        <Chip
          kind="filter"
          role="button"
          tabIndex={0}
          aria-pressed={filter}
          data-pressed={filter ? "" : undefined}
          onClick={() => setFilter((value) => !value)}
        >
          Only mine
        </Chip>
        <Chip kind="suggestion" role="button" tabIndex={0}>
          Add a cover
        </Chip>
      </div>
    </div>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/chip.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install class-variance-authority cn lucide-react
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/chip.tsxchip
      components/ui/chip.tsx
      "use client"
      
      import * as React from "react"
      import { XIcon } from "lucide-react"
      import { cva, type VariantProps } from "class-variance-authority"
      import { cn } from "cn"
      
      /*
        One Chip for every compact, interactive token (component-model.md §3):
        - kind="input": a value someone entered or picked (Combobox multiple, tag fields). Removable.
        - kind="filter": a toggle that narrows a list. Pressed state.
        - kind="suggestion": a one-tap suggestion that runs an action.
        Badge stays static (status and counts) and is not a Chip.
      */
      const chipVariants = cva(
        "chip-land inline-flex h-(--chip-height) shrink-0 items-center gap-1 rounded-(--chip-corner) px-(--chip-padding-x) text-xs whitespace-nowrap outline-none select-none focus-visible:shadow-(--focus-ring)",
        {
          variants: {
            kind: {
              input: "bg-(--chip-container) text-(--chip-label)",
              filter:
                "liquid-press bg-(--chip-filter-container) text-(--chip-label) hover:bg-(--chip-filter-container-hover) active:bg-(--chip-filter-container-pressed) data-[pressed]:bg-(--chip-container-selected) data-[pressed]:text-(--chip-label-selected) data-[pressed]:hover:bg-(--chip-container-selected-hover) disabled:bg-(--chip-container-disabled) disabled:text-(--chip-label-disabled)",
              suggestion: "liquid-press bg-(--chip-suggestion-container) text-(--chip-label) shadow-1 hover:bg-(--chip-suggestion-container-hover) disabled:bg-(--chip-container-disabled) disabled:text-(--chip-label-disabled) disabled:shadow-none",
            },
            tone: {
              neutral: "",
              danger: "bg-(--color-danger-subtle) text-(--color-danger-fg)",
              success: "bg-(--color-success-subtle) text-(--color-success-fg)",
            },
          },
          defaultVariants: { kind: "input", tone: "neutral" },
        }
      )
      
      type ChipProps = React.ComponentProps<"span"> &
        VariantProps<typeof chipVariants> & {
          /** Plays the melt-away animation (set by the parent while the chip is being removed). */
          melting?: boolean
        }
      
      function Chip({ className, kind, tone, melting, ...props }: ChipProps) {
        return (
          <span
            data-slot="chip"
            data-kind={kind ?? "input"}
            className={cn(chipVariants({ kind, tone }), melting && "chip-melt", className)}
            {...props}
          />
        )
      }
      
      function ChipRemove({ className, children, ...props }: React.ComponentProps<"button">) {
        return (
          <button
            type="button"
            data-slot="chip-remove"
            aria-label="Remove"
            className={cn(
              "hit-target liquid-press -mr-1 inline-flex size-4 items-center justify-center rounded-(--radius-pill) text-muted-foreground outline-none hover:bg-(--chip-remove-container-hover) hover:text-foreground active:bg-(--chip-remove-container-pressed) focus-visible:shadow-(--focus-ring) [&_svg]:size-3",
              className
            )}
            {...props}
          >
            {children ?? <XIcon aria-hidden />}
          </button>
        )
      }
      
      export { Chip, ChipRemove, chipVariants }
      

Imports

What the examples on this page import:

Imports
import { Chip, ChipRemove } from "@/components/ui/chip"

Anatomy

  1. 1Container · --chip-height, --chip-corner, --chip-padding-x, --chip-container.
  2. 2Label · --chip-label-size.
  3. 3Remove button · ChipRemove, input chips only.

Props

PropTypeDefaultDescription
kind"input" | "filter" | "suggestion""input"What the chip does.
tone"neutral" | "danger" | "success""neutral"Colour intent.
meltingboolean—Plays the melt-away animation.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

TokenPoints toLightDark
--chip-heightvar(--size-control-xs)24pxsame
--chip-padding-xvar(--space-2)8pxsame
--chip-cornervar(--shape-full)999pxsame
--chip-containervar(--color-bg-hover)oklch(0.965 0.005 95)oklch(0.22 0 0)
--chip-labelvar(--on-surface)oklch(0.22 0.01 260)oklch(1 0 0)
--chip-filter-containervar(--surface-container)oklch(0.965 0.005 95)oklch(0.12 0 0)
--chip-filter-container-hovercolor-mix(in oklch, var(--chip-filter-container), var(--chip-label) var(--state-hover-mix))color-mix(in oklch, var(--chip-filter-container), var(--chip-label) var(--state-hover-mix))same
--chip-filter-container-pressedcolor-mix(in oklch, var(--chip-filter-container), var(--chip-label) var(--state-pressed-mix))color-mix(in oklch, var(--chip-filter-container), var(--chip-label) var(--state-pressed-mix))same
--chip-suggestion-containervar(--surface-container-lowest)oklch(1 0 0)oklch(0.14 0 0)
--chip-suggestion-container-hovercolor-mix(in oklch, var(--chip-suggestion-container), var(--chip-label) var(--state-hover-mix))color-mix(in oklch, var(--chip-suggestion-container), var(--chip-label) var(--state-hover-mix))same
--chip-container-selectedvar(--color-brand)oklch(0.18 0.008 260)oklch(0.98 0 0)
--chip-container-selected-hovervar(--color-brand-hover)oklch(0.28 0.008 260)oklch(0.9 0 0)
--chip-label-selectedvar(--color-fg-on-accent)oklch(0.97 0.004 95)oklch(0.14 0 0)
--chip-container-disabledvar(--color-bg-disabled)color-mix(in oklch, var(--color-fg-default) var(--state-disabled-container-mix), transparent)same
--chip-label-disabledvar(--color-fg-disabled)oklch(0.62 0.01 95)oklch(0.53 0 0)
--chip-label-sizevar(--type-caption-size)11pxsame
--chip-remove-container-hovervar(--color-bg-pressed)oklch(0.94 0.007 95)oklch(0.27 0 0)
--chip-remove-container-pressedcolor-mix(in oklch, var(--color-bg-pressed), var(--chip-label) var(--state-pressed-mix))color-mix(in oklch, var(--color-bg-pressed), var(--chip-label) var(--state-pressed-mix))same

Motion

TriggerWhat happensTokens
Add / removeLands with a small pop; removal melts and neighbours slide over.--duration-fast

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • Filter chips need aria-pressed.
  • ChipRemove has a label naming the chip.

Usage

Do

  • Use for tags, filters and quick suggestions.

Don’t

  • Don't use for static status (use Badge).

Code

components/ui/chip.tsx
"use client"

import * as React from "react"
import { XIcon } from "lucide-react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"

/*
  One Chip for every compact, interactive token (component-model.md §3):
  - kind="input": a value someone entered or picked (Combobox multiple, tag fields). Removable.
  - kind="filter": a toggle that narrows a list. Pressed state.
  - kind="suggestion": a one-tap suggestion that runs an action.
  Badge stays static (status and counts) and is not a Chip.
*/
const chipVariants = cva(
  "chip-land inline-flex h-(--chip-height) shrink-0 items-center gap-1 rounded-(--chip-corner) px-(--chip-padding-x) text-xs whitespace-nowrap outline-none select-none focus-visible:shadow-(--focus-ring)",
  {
    variants: {
      kind: {
        input: "bg-(--chip-container) text-(--chip-label)",
        filter:
          "liquid-press bg-(--chip-filter-container) text-(--chip-label) hover:bg-(--chip-filter-container-hover) active:bg-(--chip-filter-container-pressed) data-[pressed]:bg-(--chip-container-selected) data-[pressed]:text-(--chip-label-selected) data-[pressed]:hover:bg-(--chip-container-selected-hover) disabled:bg-(--chip-container-disabled) disabled:text-(--chip-label-disabled)",
        suggestion: "liquid-press bg-(--chip-suggestion-container) text-(--chip-label) shadow-1 hover:bg-(--chip-suggestion-container-hover) disabled:bg-(--chip-container-disabled) disabled:text-(--chip-label-disabled) disabled:shadow-none",
      },
      tone: {
        neutral: "",
        danger: "bg-(--color-danger-subtle) text-(--color-danger-fg)",
        success: "bg-(--color-success-subtle) text-(--color-success-fg)",
      },
    },
    defaultVariants: { kind: "input", tone: "neutral" },
  }
)

type ChipProps = React.ComponentProps<"span"> &
  VariantProps<typeof chipVariants> & {
    /** Plays the melt-away animation (set by the parent while the chip is being removed). */
    melting?: boolean
  }

function Chip({ className, kind, tone, melting, ...props }: ChipProps) {
  return (
    <span
      data-slot="chip"
      data-kind={kind ?? "input"}
      className={cn(chipVariants({ kind, tone }), melting && "chip-melt", className)}
      {...props}
    />
  )
}

function ChipRemove({ className, children, ...props }: React.ComponentProps<"button">) {
  return (
    <button
      type="button"
      data-slot="chip-remove"
      aria-label="Remove"
      className={cn(
        "hit-target liquid-press -mr-1 inline-flex size-4 items-center justify-center rounded-(--radius-pill) text-muted-foreground outline-none hover:bg-(--chip-remove-container-hover) hover:text-foreground active:bg-(--chip-remove-container-pressed) focus-visible:shadow-(--focus-ring) [&_svg]:size-3",
        className
      )}
      {...props}
    >
      {children ?? <XIcon aria-hidden />}
    </button>
  )
}

export { Chip, ChipRemove, chipVariants }