Components
Details
Details is a collapsible component that allows the user to show or hide content.
<details class="ds-details">
<summary>Hvem kan registrere seg i Frivillighetsregisteret?</summary>
<div>
For å kunne bli registrert i Frivillighetsregisteret, må
organisasjonen drive frivillig virksomhet. Det er bare foreninger,
stiftelser og aksjeselskap som kan registreres. Virksomheten kan ikke
dele ut midler til fysiske personer. Virksomheten må ha et styre.
</div>
</details>const Preview = () => { return ( <Details> <Details.Summary> Hvem kan registrere seg i Frivillighetsregisteret? </Details.Summary> <Details.Content> For å kunne bli registrert i Frivillighetsregisteret, må organisasjonen drive frivillig virksomhet. Det er bare foreninger, stiftelser og aksjeselskap som kan registreres. Virksomheten kan ikke dele ut midler til fysiske personer. Virksomheten må ha et styre. </Details.Content> </Details> ); }; render(<Preview />)
Use details when
- it should be up to the user whether they choose to read the content
- you want to give examples or answer frequently asked questions
- you need to split up content to avoid too much information at once
Avoid details when
- you need to show important content that everyone should see
- you need to summarise error messages, use error summary instead
Details is the same as what many know as an accordion. The name comes from the built-in HTML element <details>, which provides good accessibility and semantics without additional JavaScript.
Example
You can use details inside a card to give the content a frame. This works well when details does not cover the whole page, or when it is only one row.
<div class="ds-card" data-variant="tinted" data-color="brand3">
<details class="ds-details">
<summary>How do I get assigned a hunter number?</summary>
<div>
You will automatically be assigned a hunter number and registered in
the Hunter Register when you have passed the hunter's exam.
</div>
</details>
<details class="ds-details">
<summary>I have forgotten my hunter number. Where can I find it?</summary>
<div>
<p class="ds-paragraph">
You can find this by logging in to
<!-- -->
<a class="ds-link" href="https://minjegerside.brreg.no/">My Page</a>
</p>
</div>
</details>
</div>
<br/>
<div class="ds-card" data-color="brand1">
<details class="ds-details">
<summary>Attachments</summary>
<div>Attachment 1, attachment 2, attachment 3</div>
</details>
</div>const InCardWithColorEn = () => { return ( <> <Card data-color='brand3' data-variant='tinted'> <Details> <Details.Summary> How do I get assigned a hunter number? </Details.Summary> <Details.Content> You will automatically be assigned a hunter number and registered in the Hunter Register when you have passed the hunter's exam. </Details.Content> </Details> <Details> <Details.Summary> I have forgotten my hunter number. Where can I find it? </Details.Summary> <Details.Content> <Paragraph> You can find this by logging in to{' '} <Link href='https://minjegerside.brreg.no/'>My Page</Link> </Paragraph> </Details.Content> </Details> </Card> <br /> <Card data-color='brand1'> <Details> <Details.Summary>Attachments</Details.Summary> <Details.Content> Attachment 1, attachment 2, attachment 3 </Details.Content> </Details> </Card> </> ); }; render(<InCardWithColorEn />)
Guidelines
Large amounts of text can be demanding for many users. Details allows users to decide for themselves what is relevant to read. However, you should not use details to hide content just to make the page look tidier. When content is hidden, there is a risk that users will not notice it at all. Carefully consider whether the content really needs to be hidden, and be clear about why you are doing so.
Avoid details inside details
It can be confusing for users to understand what is open and closed, especially when several levels can be opened at the same time.
Avoid closing other details when one details is opened
This can cause users to lose content they want to compare or return to. Only do this when it is clear to the user that only one details can be open at a time, and this behaviour is expected.
Text
Make sure the heading clearly describes what the content in details is. Headings can have a large impact on whether users find what they need, whether the content is read, and whether it can be considered accessible to all users. "Show more" or "Read more here" are not good enough titles. If you have details with many expandable sections, you can add a main heading or theme heading above the whole list.
Keep the content inside details short so it is easy to relate to the heading. If the content is too long, divide it into several details. For very large amounts of content, it may be better to create separate pages.
Edit this page on github.com (opens in a new tab)