Content presentation - Expander

Make a complex topic easier to digest by letting users reveal more detailed information only if they need it.

Open this default expander example in new window
Copy default expander code
<details class="nhsuk-details nhsuk-expander">
  <summary class="nhsuk-details__summary">
    <span class="nhsuk-details__summary-text">
      Get your medical records
    </span>
  </summary>
  <div class="nhsuk-details__text">
    <p>You can see your GP records by:</p>
    <ul>
      <li>asking for them at your GP surgery </li>
      <li>going online to see them (if you have signed up for <a href="/using-the-nhs/nhs-services/gps/gp-online-services/">GP online services</a>) </li>
    </ul>
  </div>
</details>
Close default expander code
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Nunjucks arguments for default expander
Name Type Required Description
Name text Type string Required true Description Text to be displayed on the details component.
Name html Type string Required true Description HTML content to be displayed within the details component.
Name id Type string Required false Description Id to add to the details element.
Name open Type boolean Required false Description If true, details element will be expanded.
Name classes Type string Required false Description Classes to add to the details element.
Name attributes Type object Required false Description HTML attributes (for example data attributes) to add to the details element.
Copy default expander code
{% from 'details/macro.njk' import details %}

{{ details({
  "classes": "nhsuk-expander",
  "text": "Get your medical records",
  "HTML": "
  <p>You can see your GP records by:</p>
  <ul>
    <li>asking for them at your GP surgery </li>
    <li>going online to see them (if you have signed up for <a href=\"/using-the-nhs/nhs-services/gps/gp-online-services/\">GP online services</a>) </li>
  </ul>"
}) }}
Close default expander code

When to use expanders

There are 2 ways to let users reveal more information:

Use expanders:

  • on pages where users find the amount of information overwhelming - they break down information into bite size pieces which the user can "expand", when they're ready to do so
  • for information for a wide audience, unlike the details component
  • when you see a clear user need for them

Test your content without an expander first. It may be better to:

  • simplify and reduce the amount of content
  • split the content across multiple pages
  • keep the content on a single page, separated by headings
  • use a list of links to let users navigate quickly to specific sections of content

When not to use an expander

Do not use an expander:

How expanders work

The expander is a short link in a box that expands into more detailed text when a user clicks on it.

More than 1 expander

It can work well to have several expanders. See the example below.

Open this group expander example in new window
Copy group expander code
<div class="nhsuk-expander-group">
  <details class="nhsuk-details nhsuk-expander">
    <summary class="nhsuk-details__summary">
      <span class="nhsuk-details__summary-text">
        How to measure your blood glucose levels
      </span>
    </summary>
    <div class="nhsuk-details__text">
      <p>Testing your blood at home is quick and easy, although it can be uncomfortable. It does get better.</p>
      <p>You would have been given:</p>
      <ul>
        <li>a blood glucose metre</li>
        <li>small needles called lancets</li>
        <li>a plastic pen to hold the lancets</li>
        <li>small test strips</li>
      </ul>

    </div>
  </details>

  <details class="nhsuk-details nhsuk-expander">
    <summary class="nhsuk-details__summary">
      <span class="nhsuk-details__summary-text">
        When to check your blood glucose level
      </span>
    </summary>
    <div class="nhsuk-details__text">
      <p>Try to check your blood:</p>
      <ul>
        <li>before meals</li>
        <li>2 to 3 hours after meals</li>
        <li>before, during (take a break) and after exercise</li>
      </ul>
      <p>This helps you understand your blood glucose levels and how they’re affected by meals and exercise. It should help you have more stable blood glucose levels.</p>

    </div>
  </details>

</div>
Close group expander code
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Nunjucks arguments for group expander
Name Type Required Description
Name text Type string Required true Description Text to be displayed on the details component.
Name html Type string Required true Description HTML content to be displayed within the details component.
Name id Type string Required false Description Id to add to the details element.
Name open Type boolean Required false Description If true, details element will be expanded.
Name classes Type string Required false Description Classes to add to the details element.
Name attributes Type object Required false Description HTML attributes (for example data attributes) to add to the details element.
Copy group expander code
{% from 'details/macro.njk' import details %}

<div class="nhsuk-expander-group">
  {{ details({
    "classes": "nhsuk-expander",
    "text": "How to measure your blood glucose levels",
    "HTML": "
    <p>Testing your blood at home is quick and easy, although it can be uncomfortable. It does get better.</p>
    <p>You would have been given:</p>
    <ul>
      <li>a blood glucose metre</li>
      <li>small needles called lancets</li>
      <li>a plastic pen to hold the lancets</li>
      <li>small test strips</li>
    </ul>
    "
  }) }}
  {{ details({
    "classes": "nhsuk-expander",
    "text": "When to check your blood glucose level",
    "HTML": "
    <p>Try to check your blood:</p>
    <ul>
      <li>before meals</li>
      <li>2 to 3 hours after meals</li>
      <li>before, during (take a break) and after exercise</li>
    </ul>
    <p>This helps you understand your blood glucose levels and how they’re affected by meals and exercise. It should help you have more stable blood glucose levels.</p>
    "
  }) }}
</div>
Close group expander code

Make the link text short and descriptive so users can quickly work out if they need to click on it.

Research

We tested several expanders in our information about type 1 diabetes where users felt overwhelmed by the amount of information. They tested well and seemed to meet users' emotional needs. We've also tested them on other pages about health and medicines.

If you've used this component, get in touch to share your user research findings.

Help us improve this guidance

Share insights or feedback and take part in the discussion. We use GitHub as a collaboration space. All the information on it is open to the public.

Read more about how to feedback or share insights.

If you have any questions, get in touch with the service manual team.

Updated: November 2021