Accordion

Shows and hides related sections of secondary content.

On this page

This docs is LLM-friendly and available as clean Markdown.

Supported browser agents can also use WebMCP to search, read, and open these docs. Learn more

Usage

import {
  GlAccordion,
  GlAccordionItem,
} from "gitlab-ui-react/accordion";
<GlAccordion headerLevel={3}>
  <GlAccordionItem title="More options">Additional settings</GlAccordionItem>
</GlAccordion>

Default

Accordion items expand independently by default, so users can compare content from several sections. Use concise item titles that describe the content they reveal.

Example accordion

Use one to shorten a page while keeping secondary information nearby.

Single expanded item

Set autoCollapse when opening an item should close its open sibling. Use this behavior when the sections are alternatives and users do not need to compare them.

Accordion with automatic collapse

Define the problem and the desired outcome.

Expanded title

Use titleVisible when the expanded state needs a different action label. The trigger’s accessible name changes with the visible text, so both labels must remain concise and describe the same section.

Different title while expanded

This deployment was created from the main branch and targets production.

Accessibility

  • Choose headerLevel to preserve the page’s logical heading hierarchy. An item can override the level only when its position requires it.
  • Keep every title unique, concise, and descriptive of its panel. Do not rely on the chevron alone to communicate purpose.
  • The component supplies native button behavior, aria-expanded, and the trigger-to-panel relationship. Do not override these attributes.
  • Keyboard focus remains on the trigger after it expands or collapses. Keep the visible focus indicator intact.
  • Do not hide critical information or a page’s primary action in an accordion, and do not nest accordions to create a hierarchy.

API

These are the component-specific props. Both components forward supported div attributes and refs to their outer elements.

GlAccordion

Prop Description Default
headerLevel Required heading level, from 1 through 6, inherited by child items.
autoCollapse Closes another open item when an item is expanded. false
children Accordion items to render.

GlAccordionItem

Prop Description Default
title Required text displayed by the collapsed trigger.
titleVisible Replaces title while the item is expanded. null
defaultVisible Sets the initial expansion state of an uncontrolled item. false
visible Controls whether the item is expanded.
onVisibleChange Runs with the requested expansion state after user interaction or automatic sibling collapse.
value Stable identifier used to coordinate sibling items; one is generated when omitted.
headerLevel Overrides the inherited heading level for this item. Outside an accordion, the fallback is 3. inherited
headerClass Adds clsx-compatible classes to the item’s heading.
children Content displayed in the expandable panel.