> Markdown version of [Accordion](https://vaadin.com/docs/v14/ds/components/accordion). Section index: [llms.txt](https://vaadin.com/docs/v14/ds/llms.txt)

# Accordion

Accordion is a vertically stacked set of expandable panels. It reduces clutter and helps maintain the user’s focus by showing only the relevant content at a time.

`AccordionBasic.java`

```java
Accordion accordion = new Accordion();

Span name = new Span("Sophia Williams");
Span email = new Span("sophia.williams@company.com");
Span phone = new Span("(501) 555-9128");

VerticalLayout personalInformationLayout = new VerticalLayout(name, email, phone);
personalInformationLayout.setSpacing(false);
personalInformationLayout.setPadding(false);

accordion.add("Personal information", personalInformationLayout);
```

## <a id="anatomy"></a>Anatomy

Accordion consists of stacked panels, each composed of two parts: a summary and a content area. Only one panel can be expanded at a time. (The [Details](https://vaadin.com/docs/v14/ds/components/details.md) component can be used to allow multiple simultaneously expanded sections.)

### <a id="summary"></a>Summary

The summary is the part that is always visible, and typically describes the contents, for example, with a title. Clicking on the summary toggles the content area’s visibility.

The summary supports rich content and can contain any component. This can be utilized, for example, to display the status of the corresponding content.

`AccordionSummary.java`

```java
AccordionPanel customDetailsPanel = accordion.add(CUSTOMER_DETAILS,  customerDetailsFormLayout);
customDetailsPanel.addOpenedChangeListener(e -> {
    if(e.isOpened()) {
        customDetailsPanel.setSummaryText(CUSTOMER_DETAILS);
    } else if(personBinder.getBean() != null) {
        Person personValues = personBinder.getBean();
        customDetailsPanel.setSummary(createSummary(CUSTOMER_DETAILS,
            personValues.getFirstName() + " " + personValues.getLastName(),
            personValues.getEmail(),
            personValues.getAddress() != null ? personValues.getAddress().getPhone() : ""
        ));
    }
});
```

### <a id="content"></a>Content

This is the collapsible part of a panel. It can contain any component. When the content area is collapsed, the content is invisible and inaccessible by keyboard or screen reader.

`AccordionContent.java`

```java
Accordion accordion = new Accordion();

accordion.add("Analytics", createContent(
    createStyledAnchor("#", "Dashboard"),
    createStyledAnchor("#", "Reports"),
    createStyledAnchor("#", "Data sources")
));
```

## <a id="theme-variants"></a>Theme Variants

Accordion has three theme variants: `filled`, `small` and `reverse`. Set the theme attribute separately for each panel, not on Accordion itself. Theme names can be combined with each other, for example, all three themes `filled`, `small`, and `reverse` can be applied to a panel.

### <a id="filled-panels"></a>Filled Panels

The `filled` theme variant makes the panel’s boundaries visible, which helps tie its content together visually and distinguishes it from the surrounding UI.

`AccordionFilledPanels.java`

```java
Accordion accordion = new Accordion();
AccordionPanel personalInfoPanel = accordion.add("Personal information", personalInformationLayout);
personalInfoPanel.addThemeVariants(DetailsVariant.FILLED);
```

### <a id="small-panels"></a>Small Panels

Use the `small` theme variant for compact UIs.

`AccordionSmallPanels.java`

```java
AccordionPanel paymentPanel = accordion.add("Payment", paymentLayout);
paymentPanel.addThemeVariants(DetailsVariant.SMALL);
```

### <a id="reverse-panels"></a>Reverse Panels

The `reverse` theme variant places the toggle icon after the summary contents, which can be useful for visually aligning the summary with other content.

`AccordionReversePanels.java`

```java
AccordionPanel paymentPanel = accordion.add("Payment", paymentLayout);
paymentPanel.addThemeVariants(DetailsVariant.REVERSE);
```

## <a id="disabled-panels"></a>Disabled Panels

Accordion panels can be disabled to prevent them from being expanded or collapsed. Details can be disabled to prevent them from being expanded or collapsed. Components inside a disabled expanded panel are automatically disabled as well.

`AccordionDisabledPanels.java`

```java
Accordion accordion = new Accordion();
AccordionPanel billingAdressPanel = accordion.add("Billing address", billingAddressLayout);
billingAdressPanel.setEnabled(false);
```

## <a id="best-practices"></a>Best Practices

- Accordions are suitable when users need to focus on smaller pieces of content at a time. However, when the whole content is relevant to the user to make a decision, Accordions should be avoided.

- Contents that are logically linked should be grouped together in one panel.

- Accordions are better suited for long labels compared to Tabs. However, Accordions can feel “jumpy” as panels are toggled (if there are a lot of panels or the panel content is long).

- Details can be used instead of Accordion when there is a need to see content from multiple panels simultaneously.

- Accordions can be used to break a complex form into smaller step-by-step sections.

## <a id="related-components"></a>Related Components

| Component                                                       | Usage recommendations                                                  |
| --------------------------------------------------------------- | ---------------------------------------------------------------------- |
| [Details](https://vaadin.com/docs/v14/ds/components/details.md) | Single collapsible panel.                                              |
| [Tabs](https://vaadin.com/docs/v14/ds/components/tabs.md)       | Component for organizing and grouping content into navigable sections. |

`A9679DB2-C376-4307-B391-0AEFF5F611FD`
