Skip to main content

Overview

The Accordion component creates collapsible sections that can be expanded or collapsed by the user. It’s useful for organizing content and reducing visual clutter by hiding less frequently accessed options.

Basic usage

Parameters

str
The label of the accordion which is displayed when the accordion is collapsed.
bool
default:"False"
If True, the accordion is expanded by default. If False, it is collapsed.
bool
default:"True"
If False, accordion will be hidden.
str | None
default:"None"
An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
list[str] | str | None
default:"None"
An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
bool
default:"True"
If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.

Behavior

Default state

By default, accordions are collapsed. You can change this:

Examples

Organizing settings

Group related settings in collapsible sections:

Help sections

Provide optional help text without cluttering the interface:

Progressive disclosure

Show basic options first, hide advanced ones:

Programmatically toggle accordion

Open or close accordions based on user actions:

Multiple accordions

Create a FAQ-style interface:
""") with gr.Accordion(“Can I customize the appearance?”, open=False): gr.Markdown(""" Yes! Gradio supports custom CSS and theming to match your brand. """) with gr.Accordion(“Is Gradio free?”, open=False): gr.Markdown(""" Yes, Gradio is open source and free to use under the Apache 2.0 license. """) demo.launch()

Data sections

Organize different data inputs:

Methods

update

Update the accordion’s properties:

Notes

Accordions are useful for progressive disclosure - showing basic options upfront while keeping advanced features accessible but hidden until needed.
Use descriptive labels for your accordions. Adding emoji icons can help users quickly identify the purpose of each section.
Consider starting with the most commonly used accordion open (open=True) to guide users to the most important settings.