Introducing PrimeReact v11-alpha 🎉Discover Now

Accordion

An unstyled, accessible accordion component with compound composition.

Build fully custom collapsible content sections with complete control over layout and styling.

basic-demo

Pre-styled Versions

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

Features#

  • Compound component API with six sub-components: Root, Panel, Header, Trigger, Content, Indicator
  • Single or multiple panel expansion

Usage#

import { Accordion } from 'primereact/accordion';
<Accordion.Root>
    <Accordion.Panel>
        <Accordion.Header>
            <Accordion.Trigger>
                <Accordion.Indicator />
            </Accordion.Trigger>
        </Accordion.Header>
        <Accordion.Content />
    </Accordion.Panel>
</Accordion.Root>

Behavior#

Motion Animation#

Use motionProps on Root to configure open/close animations.

<Accordion.Root motionProps={{ name: 'accordion-slide', cssVarPrefix: 'accordion-content', hideStrategy: 'none' }}>...</Accordion.Root>

See Motion for animation phases, CSS variables, and hide strategies.

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element or use a custom React component.

<Accordion.Root as="section">
    <Accordion.Panel as="article">
        <Accordion.Header as="h3">
            <Accordion.Trigger as="div">...</Accordion.Trigger>
        </Accordion.Header>
        <Accordion.Content as="section">...</Accordion.Content>
    </Accordion.Panel>
</Accordion.Root>

Custom components receive all the props that would be applied to the default element:

<Accordion.Trigger as={MyCustomButton}>...</Accordion.Trigger>

Default elements: Root=div, Panel=div, Header=div, Trigger=button, Content=div, Indicator=span.

Render Function Children#

Content accepts a render function as children, providing access to the component instance. The instance exposes accordion (root instance), accordionpanel (parent panel instance), and motion (animation state).

<Accordion.Content>{(instance) => <div>Panel is {instance.accordionpanel?.state.open ? 'open' : 'closed'}</div>}</Accordion.Content>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

AccordionRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AccordionRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AccordionRootInstance) => 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.
instanceAccordionRootInstance—
The instance to pass to the component.
ptSafeRecord<AccordionRootPassThrough>—
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: AccordionRootInstance) => 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.
defaultValuestring | number | (string | number)[]—
Default value of the active panel or an array of values in multiple mode.
valuestring | number | (string | number)[]—
Value of the active panel or an array of values in multiple mode.
multiplebooleanfalse
When enabled, multiple tabs can be activated at the same time.
disabledbooleanfalse
When disabled, the component cannot be interacted with.
openOnFocusbooleanfalse
When enabled, the accordion panel will be opened on focus.
lazybooleanfalse
When enabled, hidden tabs are not rendered at all. Defaults to false that hides tabs with css.
motionPropsMotionOptions & Pick<useMotionProps, "hideStrategy">—
Used to configure the motion of the accordion content.
tabIndexnumber0
Index of the element in tabbing order.
onValueChange(event: AccordionRootValueChangeEvent) => void—
Callback fired when the accordion's value changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"accordion"
data-part"root"
data-disabledPresent when disabled

Defines passthrough(pt) options of Accordion component.

labeltypedescription
rootAccordionRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
panelAccordionRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the panel's DOM element.
headerAccordionRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the header's DOM element.
triggerAccordionRootPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the trigger's DOM element.
contentAccordionRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content's DOM element.
contentOuterAccordionRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content outer wrapper's DOM element.
contentInnerAccordionRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content inner wrapper's DOM element.
indicatorAccordionRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the indicator's DOM element.

AccordionPanel#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AccordionPanelInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AccordionPanelInstance) => 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.
instanceAccordionPanelInstance—
The instance to pass to the component.
ptSafeRecord<AccordionPanelPassThrough>—
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: AccordionPanelInstance) => 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.
valuestring | number—
Unique value of item.
disabledbooleanfalse
Whether the item is disabled.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"accordion"
data-part"panel"
data-openPresent when expanded
data-closedPresent when collapsed
data-disabledPresent when disabled

Defines passthrough(pt) options of AccordionPanel component.

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

AccordionHeader#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AccordionHeaderInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AccordionHeaderInstance) => 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.
instanceAccordionHeaderInstance—
The instance to pass to the component.
ptSafeRecord<AccordionHeaderPassThrough>—
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: AccordionHeaderInstance) => 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.
AttributeValue
data-scope"accordion"
data-part"header"
data-openPresent when expanded
data-closedPresent when collapsed

Defines passthrough(pt) options of AccordionHeader component.

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

AccordionTrigger#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AccordionTriggerInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AccordionTriggerInstance) => 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.
instanceAccordionTriggerInstance—
The instance to pass to the component.
ptSafeRecord<AccordionTriggerPassThrough>—
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: AccordionTriggerInstance) => 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.
AttributeValue
data-scope"accordion"
data-part"trigger"
data-content-openPresent when content open
data-content-closedPresent when content closed
data-disabledPresent when disabled

Defines passthrough(pt) options of AccordionTrigger component.

labeltypedescription
rootAccordionTriggerPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

AccordionContent#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AccordionContentInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AccordionContentInstance) => 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.
instanceAccordionContentInstance—
The instance to pass to the component.
ptSafeRecord<AccordionContentPassThrough>—
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: AccordionContentInstance) => 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.
AttributeValue
data-scope"accordion"
data-part"content"
data-openPresent when expanded
data-closedPresent when collapsed
data-disabledPresent when disabled

Defines passthrough(pt) options of AccordionContent component.

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

AccordionIndicator#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AccordionIndicatorInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AccordionIndicatorInstance) => 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.
instanceAccordionIndicatorInstance—
The instance to pass to the component.
ptSafeRecord<AccordionIndicatorPassThrough>—
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: AccordionIndicatorInstance) => 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.
match"open" | "closed"—
Determines the visibility of the indicator based on the state of the accordion panel. Valid values are: - "open": Indicator is visible when the panel is expanded. - "closed": Indicator is visible when the panel is collapsed.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"accordion"
data-part"indicator"
data-openPresent when expanded
data-closedPresent when collapsed

Defines passthrough(pt) options of AccordionIndicator component.

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

Accessibility#

Screen Reader#

Accordion headers are buttons. They use aria-controls to reference the content region and aria-expanded to reflect visibility state. The announced label can be customized with aria-label or aria-labelledby via pt.

The content uses role="region" and an id that matches the header button's aria-controls.

Header Keyboard Support#

KeyFunction
tabMoves focus to the next focusable element in the page tab sequence.
shift + tabMoves focus to the previous focusable element in the page tab sequence.
enterToggles the visibility of the content.
spaceToggles the visibility of the content.
down arrowMoves focus to the next header. If focus is on the last header, moves focus to the first header.
up arrowMoves focus to the previous header. If focus is on the first header, moves focus to the last header.
homeMoves focus to the first header.
endMoves focus to the last header.