Language selection

Search


Expand/Collapse design pattern: Canada.ca design

The expand/collapse pattern (also known as accordion) allows content to be hidden until requested. The pattern consists of a trigger link that shows or hides the content.

Example:

You must click on this area to expand and collapse the content

This text is hidden until it is revealed.

On this page

When to use

The expand/collapse pattern can be used in two situations:

1. Presenting a choice between mutually exclusive answers

Use this pattern when people need to get different answers depending on their situation and when these answers are mutually exclusive.

This reduces the risk of having people wrongly think they got the answer that applies to their situation.

2. Presenting secondary information

Use this pattern to prevent secondary content from interfering with the main task.

This can be content that applies to most people, but that only a few people may need to use (for example, a privacy statement or additional details not needed to accomplish the main task).

It can also be content that applies only to a minority of people (such as when there is specific information for a specific audience).

Using expand all/collapse all buttons

Long description below the image
Long description

Two grey buttons positioned side-by-side. Both have grey backgrounds. The button on the left has the text: Expand all. The button on the right has the text: Collapse all.

The expand all/collapse all option should only be used if it may benefit users to expose all information at once. This may include on a page containing many expand/collapse patterns with:

What to avoid

Don't use this pattern if:

Design specifications

Expand all/collapse all pattern

By default, all patterns should be closed.

Copy the code for the expand all/collapse all pattern.

Expand all/collapse all buttons

When clicked:

Copy the code for the expand all/collapse all buttons.

How to implement

Implementation notes

Implementations

Determine what best suits the type of page you're creating.

Presenting a choice between mutually exclusive answers

Determine if you are in a shared custody situation

Does the child spend their time:

  • about equally between both parents

    If the child shares their time about equally between the parents, then both parents are considered to have shared custody of that child...

  • mostly with you

    If the child lives with you most of the time, you are considered to have primary custody for the purposes of the Canada child benefit...

  • mostly with the other parent

    If the child lives with the other parent most of the time, the other parent is considered to have primary custody for the purposes of the Canada child benefit...

Code
<h3>Determine if you are in a shared custody situation</h3>
<p>Does the child spend their time:</p>
<ul class="list-unstyled">
 <li>
  <details>
   <summary>about equally between both parents</summary>
   <p>If the child shares their time about equally between the parents, then both parents are considered to have <strong>shared custody</strong> of that child...</p>
  </details>
 </li>
 <li>
  <details>
   <summary>mostly with you</summary>
   <p>If the child lives with you most of the time, you are considered to have <strong>primary custody</strong> for the purposes of the Canada child benefit...</p>
  </details>
 </li>
 <li>
  <details>
   <summary>mostly with the other parent</summary>
   <p>If the child lives with the other parent most of the time, the other parent is considered to have <strong>primary custody</strong> for the purposes of the Canada child benefit...</p>
  </details>
 </li>
</ul>

Presenting secondary information

Estimate your payments

Use the estimator to help you plan your budget.

For example, you can estimate what amount you would get if:

  • you have a new child
  • your income changes
  • you start or end shared custody
See the math behind Canada child benefit payments

How are payments calculated

Every month, Canada child benefit payments are adjusted based on:

  • the number of children in your care
  • the age of your children
  • your marital status
  • your family net income from the previous year

...

Code
<h3>Estimate your payments</h3>
<p>Use the estimator to help you plan your budget.</p>
<p>For example, you can estimate what amount you would get if:</p>
<ul>
 <li>you have a new child</li>
 <li>your income changes</li>
 <li>if you start or end shared custody</li>
</ul>
<details>
 <summary>See the math behind Canada child benefit payments</summary>
 <h3>How are payments calculated</h3>
 <p>Every month, Canada child benefit payments are adjusted based on:</p>
 <ul>
  <li>the number of children in your care</li>
  <li>the age of your children</li>
  <li>your marital status</li>
  <li>your family net income from the previous year</li>
 </ul>
 <p>...</p>
</details>

With expand all / collapse all

[Information by category]

Topic 1 that is applicable to many
  • [Task link 1]
  • [Task link 2]
  • [Task link 3]
  • ...
Topic 2 that is applicable to many
  • [Task link 1]
  • [Task link 2]
  • [Task link 3]
  • ...
Topic 3 that is applicable to many
  • [Task link 1]
  • [Task link 2]
  • [Task link 3]
  • ...
...

...

Code
<h4>[Information by category]</h4>
<div class="btn-group mrgn-bttm-sm mrgn-tp-md">
  <button type="button" class="btn btn-default wb-toggle" data-toggle="{&quot;selector&quot;: &quot;details&quot;, &quot;parent&quot;: &quot;#expand-collapse&quot;, &quot;type&quot;: &quot;on&quot;}">Expand all</button>

  <button type="button" class="btn btn-default wb-toggle" data-toggle="{&quot;selector&quot;: &quot;details&quot;, &quot;parent&quot;: &quot;#expand-collapse&quot;, &quot;type&quot;: &quot;off&quot;}">Collapse all</button>
</div>
<div id="expand-collapse">
  <details>
    <summary>Topic 1 that is applicable to many</summary>
    <ul>
      <li>[Task link 1]</li>
      <li>[Task link 2]</li>
      <li>[Task link 3]</li>
      <li>...</li>
    </ul>
  </details>
  <details>
    <summary>Topic 2 that is applicable to many</summary>
    <ul>
      <li>[Task link 1]</li>
      <li>[Task link 2]</li>
      <li>[Task link 3]</li>
      <li>...</li>
    </ul>
  </details>
  <details>
    <summary>Topic 3 that is applicable to many</summary>
    <ul>
      <li>[Task link 1]</li>
      <li>[Task link 2]</li>
      <li>[Task link 3]</li>
      <li>...</li>
    </ul>
  </details>
  <details>
    <summary>...</summary>
  </details>
</div>

Research and rationale

We successfully tested the use of the expand/collapse pattern to encourage people to choose between mutually exclusive options during two optimization projects with the Canada Revenue Agency.

Latest changes

Added information about when to include expand all/collapse all buttons. Also added implementation notes.
Guidance was changed to allow the use of expand/collapse for mutually exclusive answers.

Page details

Date modified: