Next Chapter Begins 🚀Read the full story

Chip

An unstyled chip component with compound composition for representing entities.

Build fully custom chip elements with complete control over layout and styling.

Apple
Ioni
Ioni Bowcher
Removable
basic-demo

Pre-styled Versions

Choose a pre-styled library to use Chip with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with five sub-components: Root, Start, Label, End, Remove
  • Built-in visibility state, chip hides itself when removed
  • onRemove callback for reacting to dismissal events
  • Remove sub-component with keyboard support (Enter, Backspace)

Usage#

import { Chip } from 'primereact/chip';
<Chip.Root>
    <Chip.Start />
    <Chip.Label />
    <Chip.End>
        <Chip.Remove />
    </Chip.End>
</Chip.Root>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Chip.Root as="span">
    <Chip.Label as="span">Tag</Chip.Label>
</Chip.Root>

Default elements: Root=div, Start=div, Label=div, End=div, Remove=span.

Render Function Children#

Sub-components accept a render function as children, providing access to the component instance.

<Chip.Label>{(instance) => <span>{instance.chip?.state.visible ? 'Visible' : 'Hidden'}</span>}</Chip.Label>

Pass Through#

The component's PT demo referenced as chip-pt is unavailable or does not exist.

API#

ChipRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ChipRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ChipRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceChipRootInstance—
The instance to pass to the component.
ptSafeRecord<ChipRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ChipRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
onRemove(event: ChipRootRemoveEvent) => void—
Callback fired when the chip is removed.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scopechip
data-partroot

Defines passthrough(pt) options of Chip component.

labeltypedescription
rootChipRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
labelChipRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the label's DOM element.
removeChipRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the remove's DOM element.
startChipRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the start's DOM element.
endChipRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the end's DOM element.

ChipStart#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ChipStartInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ChipStartInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceChipStartInstance—
The instance to pass to the component.
ptSafeRecord<ChipStartPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ChipStartInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ChipStart component.

labeltypedescription
rootChipStartPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

ChipLabel#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ChipLabelInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ChipLabelInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceChipLabelInstance—
The instance to pass to the component.
ptSafeRecord<ChipLabelPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ChipLabelInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ChipLabel component.

labeltypedescription
rootChipLabelPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ChipEnd#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ChipEndInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ChipEndInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceChipEndInstance—
The instance to pass to the component.
ptSafeRecord<ChipEndPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ChipEndInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ChipEnd component.

labeltypedescription
rootChipEndPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

ChipRemove#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ChipRemoveInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ChipRemoveInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceChipRemoveInstance—
The instance to pass to the component.
ptSafeRecord<ChipRemovePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ChipRemoveInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ChipRemove component.

labeltypedescription
rootChipRemovePassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

Chip uses its label content as the default accessible name. Provide aria-label or aria-labelledby on Chip.Root to override. Removable chips have a focusable remove element with tabIndex="0".

Keyboard Support#

KeyFunction
enterHides removable chip
backspaceHides removable chip