New block: Accordion block
There's been a few requests for an Accordion block in core. Let's start exploring how this looks.
Requirements
- Pure CSS.
- Add accordion headers with arrow icons.
- Allow any block to be added within an accordion section.
Is the accordion section simply a Group block that is able to be collapsed? Basically it would work similarly to the Settings sidebar sections.

Kudos to @melchoyce for this idea. Some examples she shared recently:
https://codepen.io/raubaca/pen/PZzpVe https://codepen.io/vinsongrant/pen/qbGKed https://codepen.io/abergin/pen/ihlDf
Great! Yeah this is needed. I have seen a few requests over a longer period of time asking for an accordion block.
If there is a fallback for IE, it could be a details element, reducing the markup drastically. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details
Actually accordions don't need CSS, JS etc... We could simply use a <details> HTML element.
<details>
<summary>This is the accordion title</summary>
This is the accordion content
</details>
^ The above code would render like this:
This is the accordion title
This is the accordion contentCoincidentally I started building a details block yesterday and it works fine that way.
We can add options to change the styling of the triangle etc if needed, and there's some extra info on this article
Note: accordions built this way are 100% accessible and they just work because native-HTML :smile:
Edit: It looks like I was writing this comment at the same time as @carolinan above :laughing:
We could do a render fallback on the server for IE, or also consider not doing anything (it'll still render the content, just expanded by default).
having it expanded by default in IE is not a big issue... As long as it renders and looks OK I don't think we should add any extra scripts etc to make IE behave like modern browsers. Supporting IE is not the same as making it look & behave identically :+1:
Here are some plugin examples that use accordion blocks. Twenty Twenty. Gutenberg plugin activated.
Atomic Blocks https://wordpress.org/plugins/atomic-blocks/
Backend:

Title selected:

Content selected:

Frontend:

Co Blocks https://wordpress.org/plugins/coblocks/
Backend.
Title is selected.

Content is selected:

To add a new accordion one clicks the Inserter area similar to the Group Block.
Frontend:

Accordion Blocks by Phil Buchanan https://wordpress.org/plugins/accordion-blocks/
Backend.
Title selected.

Content selected.

Frontend.
There is a minus on the right side when the accordion is open. When the accordion is closed there is a + sign.

It's worth noting that using heading elements in the <summary> is valid, and that would be the correct way to handle a lot of use-cases for accordions like step-by-step how-to articles.
Should the Accordion block have an option to switch the contents of the <summary> from plain (no inner elements other than text) to different heading levels (similar to the options provided in the Heading block); or should the <summary> be an entire InnerBlocks area where you can insert whatever typography-related block you want?
I'm currently leaning towards the former solution, since it's less complicated, and it's much easier to migrate from that to the latter solution in the future than to go the other way around.
The only thing with IE11 and <details> HTML element is they are expanded by default as mentioned. The problem with that is it defeats the purpose of toggles.
The only thing with IE11 and
<details>HTML element is they are expanded by default as mentioned. The problem with that is it defeats the purpose of toggles.
IE11 doesn't break with a <details> element... and sure, it's not the same as it is in a modern browser but that's not a dealbreaker.
Nobody on IE expects to see the same thing they'd see when using Firefox/Chrome/Brave/Whatever. Different browsers exists for different people, different tastes and needs or limitations. If they use IE, then the rest of the planet shouldn't suffer for it.
A workaround could be implemented for IE by loading a conditional script that would tweak the behaviour, but... is it really worth it? Adding extra html & JS in other browsers just to make IE work would do a lot more damage overall, and we can't really move forward if we keep looking at a broken thing from 7 years ago.
They can still see the content, they can read everything, things are properly styled, just not collapsed by default.
I understand what your saying @aristath I just have a very strange requirements with a project right now which only supports IE11 ! yea...it is an internal site like a intranet type. The content editor wanted some toggles..
And there is still years of support for IE11 :(
https://death-to-ie11.com/
This issue and related PR were discussed today by the Accessibility team.
The team suggests to not use the <details> element for this scenario, and instead follow the ARIA Authoring Practices implementation for an accordion component
For more details on why <details> is not a suitable element, please see:
- https://daverupert.com/2019/12/why-details-is-not-an-accordion/
- https://adrianroselli.com/2019/04/details-summary-are-not-insert-control-here.html
As always, please feel free to ping the team in the #accessibility Make WordPress Slack channel if there are further questions or comments.
Here's an iteration on the Accordion block.

That looks pretty good. One thing we'll need to make sure to include in the block's toolbar is a way to switch the HTML element of the heading, including h1-h6 options, plus maybe even p? We should be able to extract the heading level control from the Heading block and reuse it here.
Here's a prototype of how I imagine this block working.

- It uses similar block interactions as the Group and Heading blocks.
- The Accordion heading allows a heading level change.
- The large
+Inserter button below works like the Group block.
- The heading is editable on focus of the Accordion block.
- Adding content to the collapsable region requires clicking the
+Inserter to add a block. - When resting, the Accordion block collapses to hide the content region.
- When focused, the Accordion block open to show the content.
Some recent design feedback lead me to add a couple Style Variations.
Default

Style Variation 1

Style Variation 2

Further design feedback from @melchoyce suggested that we just drop a Paragraph block into the content area rather than a big + button. The flow would look something like this.

Recent design feedback:
Arrows
The arrows need to be oriented differently. Rather than up/down, they should be right/down.

Style variations
There's some question as to whether or not the variations above make sense to include as style variations. I'm waffling back and forth on this one. They are "style" variations that only manipulate styling... so that makes sense to me.
Default variation
Should the above Style Variation 2 actually be the default because there's basically no styling? It might make it easier to themes to apply their own styles with that as the default.
Yeah, I'd favor a default style that's easy for themes to override.
Here is a draft PR for the Details Block: https://github.com/WordPress/gutenberg/pull/23940 There is some crossover of the Accordion and the Details Blocks.
Looking good. Liking the iterations so far and how this is evolving. Some feedback:
- Add the interaction/flow for adding an additional accordion section
- Add the interaction/flow for adding an additional block within the accordion content
- Add block settings for accordion
To summarize above: I think it would be good to see the full block adding flow in context with the sidebar and its settings
- I would also push the styles a bit more. Right now they are very subtle and I wouldn't consider them a different style, more just removing/adding background+border colors. Try playing more with layout, spacing, position of elements. Similar to this approach: https://github.com/WordPress/gutenberg/issues/22071#issuecomment-624637501