This is the content for Writing well for the web.
Accordion
The accordion component lets users show and hide sections of related content on a page.
This is the content for Writing well for specialists.
This is the content for Know your audience.
This is the content for How people read.
<div
class="govuk-accordion"
data-module="govuk-accordion"
id="accordion-default"
>
<div class="govuk-accordion__section">
<div class="govuk-accordion__section-header">
<h2 class="govuk-accordion__section-heading">
<span
class="govuk-accordion__section-button"
id="accordion-default-heading-1"
>
Writing well for the web
</span>
</h2>
</div>
<div
id="accordion-default-content-1"
class="govuk-accordion__section-content"
>
<p class="govuk-body">
This is the content for Writing well for the web.
</p>
</div>
</div>
<div class="govuk-accordion__section">
<div class="govuk-accordion__section-header">
<h2 class="govuk-accordion__section-heading">
<span
class="govuk-accordion__section-button"
id="accordion-default-heading-2"
>
Writing well for specialists
</span>
</h2>
</div>
<div
id="accordion-default-content-2"
class="govuk-accordion__section-content"
>
<p class="govuk-body">
This is the content for Writing well for specialists.
</p>
</div>
</div>
<div class="govuk-accordion__section">
<div class="govuk-accordion__section-header">
<h2 class="govuk-accordion__section-heading">
<span
class="govuk-accordion__section-button"
id="accordion-default-heading-3"
>
Know your audience
</span>
</h2>
</div>
<div
id="accordion-default-content-3"
class="govuk-accordion__section-content"
>
<p class="govuk-body">This is the content for Know your audience.</p>
</div>
</div>
<div class="govuk-accordion__section">
<div class="govuk-accordion__section-header">
<h2 class="govuk-accordion__section-heading">
<span
class="govuk-accordion__section-button"
id="accordion-default-heading-4"
>
How people read
</span>
</h2>
</div>
<div
id="accordion-default-content-4"
class="govuk-accordion__section-content"
>
<p class="govuk-body">This is the content for How people read.</p>
</div>
</div>
</div>
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.
Name | Type | Description |
---|---|---|
id | string | Required. Must be unique across the domain of your service if |
headingLevel | integer | Heading level, from |
classes | string | Classes to add to the accordion. |
attributes | object | HTML attributes (for example data attributes) to add to the accordion. |
rememberExpanded | boolean | Whether the expanded/collapsed state of the accordion should be saved when a user leaves the page and restored when they return. Default is |
hideAllSectionsText | string | The text content of the 'Hide all sections' button at the top of the accordion when all sections are expanded. |
hideSectionText | string | The text content of the 'Hide' button within each section of the accordion, which is visible when the section is expanded. |
hideSectionAriaLabelText | string | Text made available to assistive technologies, like screen-readers, as the final part of the toggle's accessible name when the section is expanded. Defaults to |
showAllSectionsText | string | The text content of the 'Show all sections' button at the top of the accordion when at least one section is collapsed. |
showSectionText | string | The text content of the 'Show' button within each section of the accordion, which is visible when the section is collapsed. |
showSectionAriaLabelText | string | Text made available to assistive technologies, like screen-readers, as the final part of the toggle's accessible name when the section is collapsed. Defaults to |
items | array | Required. The sections within the accordion. See items. |
Name | Type | Description |
---|---|---|
heading | object | Required. The heading of each accordion section. See heading. |
summary | object | The summary line of each accordion section. See summary. |
content | object | Required. The content of each accordion section. See content. |
expanded | boolean | Sets whether the section should be expanded when the page loads for the first time. Defaults to |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
Name | Type | Description |
---|---|---|
text | string | The summary line text content of each section. If |
html | string | The summary line HTML content of each section. The summary line is inside the HTML |
{% from "moduk/components/accordion/macro.njk" import modukAccordion -%}
{{ modukAccordion({
id: "accordion-default",
items: [
{
heading: {
text: "Writing well for the web"
},
content: {
html: "<p class='govuk-body'>This is the content for Writing well for the web.</p>"
}
},
{
heading: {
text: "Writing well for specialists"
},
content: {
html: "<p class='govuk-body'>This is the content for Writing well for specialists.</p>"
}
},
{
heading: {
text: "Know your audience"
},
content: {
html: "<p class='govuk-body'>This is the content for Know your audience.</p>"
}
},
{
heading: {
text: "How people read"
},
content: {
html: "<p class='govuk-body'>This is the content for How people read.</p>"
}
}
]
}) -}}
See GOV.UK accordion component guidance for:
- when to use this component
- when not to use it
- how it works
Changes from the GOV.UK version
MOD.UK Design System components are closely based on GOV.UK Design System components.
For this component we’ve changed the font.
Have you tested this component?
Let us know how we could improve this component or share your user research findings.
Email the MOD.UK Design System team at design-system@digital.mod.uk
Need help?
Email the MOD.UK Design System team at design-system@digital.mod.uk if you have questions or feedback.