> Markdown version of [Details](https://vaadin.com/docs/latest/components/details). Section index: [llms.txt](https://vaadin.com/docs/latest/components/llms.txt)

# Details

Details is an expandable panel for showing and hiding content from the user, to make the UI less cluttered.

**Lit** — `details-basic.ts`

```typescript
return html`
  <vaadin-details summary="Contact information" opened>
    <vaadin-vertical-layout>
      <span>Sophia Williams</span>
      <span>sophia.williams@company.com</span>
      <span>(501) 555-9128</span>
    </vaadin-vertical-layout>
  </vaadin-details>
`;
```

**Flow** — `DetailsBasic.java`

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

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

Details details = new Details("Contact information", content);
details.setOpened(true);

add(details);
```

**React** — `details-basic.tsx`

```tsx
<Details summary="Contact information" opened>
  <VerticalLayout>
    <span>Sophia Williams</span>
    <span>sophia.williams@company.com</span>
    <span>(501) 555-9128</span>
  </VerticalLayout>
</Details>
```

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

Details consist of a summary area and a content area.

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

The Summary is the part that’s always visible, and typically describes the content, 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 used, for example, to display the status of the corresponding content.

**Lit** — `details-summary.ts`

```typescript
return html`
  <vaadin-details opened>
    <vaadin-details-summary slot="summary">
      <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
        <span>Contact information</span>

        <vaadin-badge theme="error" number="2">
          <vaadin-icon slot="icon" icon="vaadin:exclamation-circle"></vaadin-icon>
          <span>errors</span>
        </vaadin-badge>
      </vaadin-horizontal-layout>
    </vaadin-details-summary>

    <vaadin-form-layout .responsiveSteps="${this.responsiveSteps}">
      <vaadin-text-field
        label="Address"
        value="4027 Amber Lake Canyon"
        colspan="2"
      ></vaadin-text-field>

      <vaadin-text-field label="ZIP code" required></vaadin-text-field>

      <vaadin-text-field label="City" required></vaadin-text-field>

      <vaadin-combo-box
        label="Country"
        item-label-path="name"
        item-value-path="id"
        .items="${this.items}"
      ></vaadin-combo-box>
    </vaadin-form-layout>
  </vaadin-details>
`;
```

**Lit** — `Country.ts`

```typescript
interface Country {
    name: string;
    abbreviation: string;
    id: number;
}
export default Country;
```

**Flow** — `DetailsSummary.java`

```java
HorizontalLayout summary = new HorizontalLayout();
summary.setAlignItems(FlexComponent.Alignment.CENTER);

Badge errorBadge = new Badge("errors", 2,
        VaadinIcon.EXCLAMATION_CIRCLE.create());
errorBadge.addThemeVariants(BadgeVariant.ERROR);

summary.add(new Text("Contact information"), errorBadge);

FormLayout content = new FormLayout();
content.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1),
        new FormLayout.ResponsiveStep("20em", 2));

TextField address = new TextField("Address");
address.setValue("4027 Amber Lake Canyon");
content.add(address, 2);

TextField zipCode = new TextField("ZIP code");
zipCode.setRequired(true);
content.add(zipCode);

TextField city = new TextField("City");
city.setRequired(true);
content.add(city);

ComboBox<Country> countries = new ComboBox<>("Country");
countries.setItems(DataService.getCountries());
countries.setItemLabelGenerator(Country::getName);
content.add(countries);

Details details = new Details(summary, content);
details.setOpened(true);

add(details);
```

**React** — `details-summary.tsx`

```tsx
<Details opened>
  <DetailsSummary slot="summary">
    <HorizontalLayout theme="spacing" style={{ alignItems: 'center' }}>
      <span>Contact information</span>

      <Badge theme="error" number={2}>
        <Icon slot="icon" icon="vaadin:exclamation-circle" />
        <span>errors</span>
      </Badge>
    </HorizontalLayout>
  </DetailsSummary>

  <FormLayout responsiveSteps={responsiveSteps}>
    <TextField label="Address" value="4027 Amber Lake Canyon" data-colspan="2" />

    <TextField label="ZIP code" required />

    <TextField label="City" required />

    <ComboBox label="Country" itemLabelPath="name" itemValuePath="id" items={items.value} />
  </FormLayout>
</Details>
```

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

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

**Lit** — `details-content.ts`

```typescript
return html`
  <vaadin-details summary="Analytics" opened>
    <vaadin-vertical-layout>
      <a href="#">Dashboard</a>
      <a href="#">Reports</a>
      <a href="#">Data sources</a>
    </vaadin-vertical-layout>
  </vaadin-details>

  <vaadin-details summary="Customers" opened>
    <vaadin-vertical-layout>
      <a href="#">Accounts</a>
      <a href="#">Contacts</a>
    </vaadin-vertical-layout>
  </vaadin-details>

  <vaadin-details summary="Finances" opened>
    <vaadin-vertical-layout>
      <a href="#">Invoices</a>
      <a href="#">Transactions</a>
      <a href="#">Statements</a>
    </vaadin-vertical-layout>
  </vaadin-details>
`;
```

**Flow** — `DetailsContent.java`

```java
Details analyticsDetails = createDetails("Analytics",
        createStyledAnchor("#", "Dashboard"),
        createStyledAnchor("#", "Reports"),
        createStyledAnchor("#", "Data sources"));

Details customersDetails = createDetails("Customers",
        createStyledAnchor("#", "Accounts"),
        createStyledAnchor("#", "Contacts"));

Details financesDetails = createDetails("Finances",
        createStyledAnchor("#", "Invoices"),
        createStyledAnchor("#", "Transactions"),
        createStyledAnchor("#", "Statements"));

add(analyticsDetails, customersDetails, financesDetails);
```

**React** — `details-content.tsx`

```tsx
<Details summary="Analytics" opened>
  <VerticalLayout>
    <a href="#" style={anchorStyle}>
      Dashboard
    </a>
    <a href="#" style={anchorStyle}>
      Reports
    </a>
    <a href="#" style={anchorStyle}>
      Data sources
    </a>
  </VerticalLayout>
</Details>

<Details summary="Customers" opened>
  <VerticalLayout>
    <a href="#" style={anchorStyle}>
      Accounts
    </a>
    <a href="#" style={anchorStyle}>
      Contacts
    </a>
  </VerticalLayout>
</Details>

<Details summary="Finances" opened>
  <VerticalLayout>
    <a href="#" style={anchorStyle}>
      Invoices
    </a>
    <a href="#" style={anchorStyle}>
      Transactions
    </a>
    <a href="#" style={anchorStyle}>
      Statements
    </a>
  </VerticalLayout>
</Details>
```

### <a id="lazy-content-flow"></a>Lazy Content Flow

Content added to a collapsed Details is created and sent to the browser even if the user never expands it. When the content is expensive to build — for example, when it loads data from a backend — create it the first time the Details is opened, using an opened change listener:

```java
Details details = new Details("Order History");
details.addOpenedChangeListener(event -> {
    if (event.isOpened() && details.getContent().findAny().isEmpty()) {
        details.add(createOrderHistory());
    }
});
```

The content check ensures that the content is created only once. After that, it stays in place when the Details is collapsed and expanded again.

### <a id="disabling"></a>Disabling

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

**Lit** — `details-disabled.ts`

```typescript
return html`
  <vaadin-details summary="Members (8)" disabled>
    <ul>
      <li>Blake Martin</li>
      <li>Caroline Clark</li>
      <li>Avery Torres</li>
      <li>Khloe Scott</li>
      <li>Camila Fisher</li>
      <li>Gavin Lewis</li>
      <li>Isabella Powell</li>
      <li>Zoe Wilson</li>
    </ul>
  </vaadin-details>
`;
```

**Flow** — `DetailsDisabled.java`

```java
UnorderedList content = new UnorderedList(new ListItem("Blake Martin"),
        new ListItem("Caroline Clark"), new ListItem("Avery Torres"),
        new ListItem("Khloe Scott"), new ListItem("Camila Fisher"),
        new ListItem("Gavin Lewis"), new ListItem("Isabella Powell"),
        new ListItem("Zoe Wilson"));

Details details = new Details("Members (8)", content);
details.setEnabled(false);

add(details);
```

**React** — `details-disabled.tsx`

```tsx
<Details summary="Members (8)" disabled>
  <ul>
    <li>Blake Martin</li>
    <li>Caroline Clark</li>
    <li>Avery Torres</li>
    <li>Khloe Scott</li>
    <li>Camila Fisher</li>
    <li>Gavin Lewis</li>
    <li>Isabella Powell</li>
    <li>Zoe Wilson</li>
  </ul>
</Details>
```

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

Use Details to group related content and to reduce the chance of overwhelming the user with information. However, avoid putting important information in a Details component unless it’s expanded by default. Otherwise, the user might not notice it.

Details can be used instead of Accordion if there’s a need to see content from multiple collapsible content areas, simultaneously.

The expandable and collapsible nature of Details can sometimes be difficult for users to discover. Use the [filled variant](https://vaadin.com/docs/latest/components/details/styling.md#filled) and apply a [tooltips](https://vaadin.com/docs/latest/components/tooltip.md) to make this more discoverable.

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

| Component                                                           | Usage Recommendation                                                                            |
| ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [Accordion](https://vaadin.com/docs/latest/components/accordion.md) | Vertically stacked set of expandable panels, in which only one panel can be expanded at a time. |
| [Tabs](https://vaadin.com/docs/latest/components/tabs.md)           | Component for organizing and grouping content into navigable sections.                          |

`25CA6A07-DDDB-47F3-9E6D-EEAB00498336`
