Make Divi Accordion Module Tabs Closable

Written by Dan Mossop

Divi includes an accordion module which lets you place content in expandable boxes, useful for things like FAQs sections. Normally Divi will always keep one accordion tab (or toggle) open, and the only way to close a tab is to open another. If you'd like your users to be able to close accordion tabs without needing to open another (i.e. so that all tabs are closed), here's how to do it.

Note: see this post if you'd like to make the Divi accordion tabs start closed by default.

Example of a Closable Accordion

The following example shows the feature in action. Click to open the accordion tabs and you'll then be able to close them again by clicking either on the toggle "close" icon, or on the toggle title itself.

How hot is the sun?
Really, really hot.
Is the moon really made of cheese?
Nope.
Do you want closable Divi accordion toggles?
Go on then.

Making Accordions Closeable using Divi Booster

Divi Booster adds hundreds of new options to Divi, including the option to make accordions closeable. This can be applied to individual modules, or to all modules at once.

Making Individual Accordions Closeable using Divi Booster 

Divi Booster adds an option to make individual accordions closeable into the Accordion Module settings. You'll find it at:

  • Divi Booster 2.9.5 upwards: "Accordion Module Settings > Design > Toggle > Closeable"
  • Divi Booster 2.8.4 – 2.9.4: "Accordion Module Settings > Design > Title Text > Closeable"

Making All Accordion Modules Closeable using Divi Booster

It is also possible to make all accordions on the site closeable using the option found under "Modules > Accordion" on the Divi Booster settings page. This option has been available since Divi Booster v1.9.9.

Make Accordion Modules Closeable using jQuery / CSS

If you don't have Divi Booster and are comfortable with adding jQuery / CSS code to Divi, you can make the accordions closable using the following method. 

Step 1: Add the following jQuery code to your site, e.g. by pasting it into the "Divi > Theme Options > Integration > Add this code to the head of you blog" box.

1<script>
2jQuery(function($){
3 $('.et_pb_toggle_title').click(function(){
4 var $toggle = $(this).closest('.et_pb_toggle');
5 if (!$toggle.hasClass('et_pb_accordion_toggling')) {
6 var $accordion = $toggle.closest('.et_pb_accordion');
7 if ($toggle.hasClass('et_pb_toggle_open')) {
8 $accordion.addClass('et_pb_accordion_toggling');
9 $toggle.find('.et_pb_toggle_content').slideToggle(700, function() {
10 $toggle.removeClass('et_pb_toggle_open').addClass('et_pb_toggle_close');
11
12 });
13 }
14 setTimeout(function(){
15 $accordion.removeClass('et_pb_accordion_toggling');
16 }, 750);
17 }
18 });
19});
20</script>

Step 2 (Optional): To add a "close" icon to the open toggles, add the following CSS code to your site, e.g. by pasting it into the "Divi > Theme Options > General > Custom CSS" box.

1.et_pb_accordion .et_pb_toggle_open .et_pb_toggle_title:before {
2 display: block!important;
3 content: "\e04f" !important;
4}

Styling the Close Icon

With any of the above methods of making accordions closeable, the close icon inherits the styles of the built in "open" icon. That means you can style both the open and close icons using the existing options in the accordion module settings, e.g.: 

If you wish to apply certain styles to the close icon only (i.e. not to the open icon), then you can do so using CSS such as this:

1/* Normal state */
2.et_pb_accordion .et_pb_toggle_open .et_pb_toggle_title:before {
3 color: grey !important;
4}
5
6/* Hover state */
7.et_pb_accordion .et_pb_toggle_open .et_pb_toggle_title:hover:before {
8 color: blue !important;
9}

The example above will make the icon grey normally, changing to blue when hovered. If you aren't sure how to get the effect you want, just give me a shout in the comments.

Adding a Second Close Icon at the Bottom of Toggles

If your accordion toggles contain a lot of text, you may want to add a second close icon at the bottom to save your users having to scroll all the way back to the top of the text to close the toggle. Here's the code to do this. It should be used in addition to either the Divi Booster / manual methods given above. The code can be placed either in a code module on the page in question, or in the "Divi > Theme Options > Integrations > Add Code to the Head of your Blog" box.

1<script>
2jQuery(function($){
3 $('.et_pb_toggle_title').each(function(){
4 var $title = $(this);
5 var $closebar = $title.clone(true).addClass('db_pb_toggle_close2').html(' ');
6 $title.closest('.et_pb_toggle').append($closebar);
7 });
8
9 $('.db_pb_toggle_close2').click(function(){ // Listen for clicks on the close bar
10 var $toggle = $(this).closest('.et_pb_toggle');
11 var mainAreaOffset = $('#et-main-area').length ? $('#et-main-area').offset().top : 0;
12 $('html, body').animate({scrollTop: $toggle.offset().top - mainAreaOffset - 16}, 700); // Scroll considering the main area's top offset
13 });
14});
15</script>
16<style>
17 .et_pb_toggle_close .db_pb_toggle_close2 {
18 display: none;
19 }
20 .db_pb_toggle_close2 {
21 margin-top: 10px;
22 visibility: hidden;
23 }
24 .db_pb_toggle_close2:before {
25 visibility: visible;
26 }
27</style>

Easily Close Tabs with Divi Booster!

Enhance your Divi accordions by making their tabs closable using Divi Booster. This user-friendly plugin allows you to add new features like closable accordions effortlessly, perfect for improving FAQ sections and content organization.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

131 Comments

  1. Please disregard my previous comment. Resolved. Thank you!

    Reply
  2. I used the code you provided on a Divi 3 site. It worked perfectly except there is no minus sign to click on. Any idea how to fix that? URL: spiritualityexplained.com/about.

    Reply
    • Hi Byron, my apologies – it looks like the CSS code needed to display the minus sign somehow went missing from the post. I've added the code to the post above. Hope that helps.

      Reply
      • That worked perfectly. Thank you!

        Reply
  3. it don´t work… :(

    Reply
    • Hi Rafo, any chance you can provide a link to the page / post you're adding it on so that I can take a look?

      Reply
  4. Hi Dan,
    I love your side, I already learned a lot. And I appreciate how much work do you do. I use the jQuery code and it works like a charme. But I do not have the minus to close the accordion. It can be closed, if you find the right spot, but I would like to have this spot marked :-)
    Greetings from Germany
    Claudia

    Reply
    • Hi Claudia – there was supposed to be some additional CSS in the post for adding the minus icon, but it disappeared from the post for some reason…! I've added it back in. If you add the CSS to your site (no need to adjust the jQuery), it should start showing the icon.

      Reply
  5. oops submitted question too quickly :-(

    Please use this instead

    Hi Naive question. I’ve added your code snippet to Divi and my accordions are opening and closing beautifully. Thank you 🙂
    However, I do not see the minus symbol to signal the close functionality to users. Where is this symbol assigned? Can I add it myself?
    Thanks!

    Reply
    • Hi Paul, I've updated the post to include the CSS needed to show the minus symbol – no need to modify the jQuery. I hope that helps.

      Reply
  6. Hi, thank you for the tips. This doesn't seem to work for me. Is it compatible with Divi 3?

    Reply
    • Dan, sorry, I figured it out. I forgot to place within script tags. Thanks!!

      Reply
      • Great, I'm glad you were able to figure it out ;)

        Reply
  7. THANK YOU DAN! I appreciate the jquery assist. Works perfectly!

    Reply
  8. Hey.
    I'm using BOoster 2.3.1 and Divi 2.7.10, but the options
    Make accordions start fully closed by default
    Make accordions closable
    has no effect.
    The first acc is open and can't closed.
    http://c6.vipdev.de/mehr-informationen/

    Reply
    • Sorry Mario, I'm too late getting to this and I see you've taken down the page. If you're still trying to get this to work, please let me know. Cheers.

      Reply
  9. Dan,
    This works, thanks! But how does the user know the accordion can be closed? There's no minus symbol or any logo to indicate that the accordion item can be closed. Am I missing something?
    James

    Reply
    • Hi James, I've just updated the post (and Divi Booster) with code to add a minus symbol to open accordion tabs. Hope that helps :)

      Reply
  10. The jQuery above doesn't seem to be working anymore.

    Reply
    • Hi Ryan, I've just checked and the code is working for me on the latest version of Divi (2.7.8). Are you able to share a link to the page you're trying to use it on? Perhaps something else, such as a JavaScript error elsewhere on the page, is preventing it from working.

      Reply
      • Hi. I wondering that it is possible to add a minus circle element (like the plus circle element that appear when the accordion is close) when the accordion get expanded. In this way, people will know that if they touch the minus element, the accordion will get close again.

        Reply
        • Hi Nicolas, the CSS I've just added to the post will add a minus circle element. Hope it helps.

          Reply
      • Hi Dan –
        I'm having the same issue. The open/close feature is working, but there is no "-" icon appearing, so users wouldn't know to click. Will probably buy the plugin, anyway, but it's sort of the principle of the thing now and I'm just curious to know what I'm doing wrong….

        Reply
        • Hi Matt – it was my mistake. I thought I had added the CSS code to the post, but it seems like it went astray somehow. I've updated the post now. If you add the CSS to your site, the icon should show up. Just leave the jQuery as it is.

          Reply
  11. Hi, Thanks for this code.
    I want to share my code for adding the close icon.
    I added somme CSS in my child theme.

    .et_pb_toggle_open:before {
    position: absolute;
    right: 20px;
    font-family: "ETmodules";
    font-size: 16px;
    color: #ccc;
    content: "\e04f";
    }

    Reply
    • Thanks for sharing Max! I posted my own variant before I saw this. Hopefully one or the other works for everyone. Cheers! :)

      Reply
  12. Is it possible to have a "-" sign after the section is expanded? It shows the plus sign to expand it, but unless someone by chance runs their mouse over that area they will have no way to know the section can be closed that way. Thanks

    Reply
    • Hi Jay, I've added CSS to the post above, which will display the "-" sign on open sections. Hope that helps.

      Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.

Latest From Divi Booster

Set Hover Color for Menu Links in the Divi Menu Module

Customizing the hover color of menu links lets you enhance the user experience and maintain visual consistency with your website’s brand. By setting a specific hover color, you can guide visitors' attention and improve navigation feedback. In this guide we show you...

Enable Automatic Looping for YouTube Videos in the Divi Video Module

Enabling automatic looping for YouTube videos in your Divi video module ensures that content plays seamlessly and continuously without interruption. This feature can enhance user engagement, highlight key information, or create dynamic visual effects on your website....

Hide Video Controls in Divi Video Module

Disabling YouTube video controls in the Divi Video Module helps create a seamless, distraction-free viewing experience for your site visitors. This approach is useful when you want full control over how your video content appears and is interacted with on the page, or...

Mute YouTube Videos by Default in the Divi Video Module

In the Divi Video Module, starting your YouTube videos muted by default can create a more user-friendly browsing experience on your webpage. It is particularly beneficial for reducing distractions, enhancing visitor engagement, and providing a seamless content preview...

Autoplay Videos in Divi Video Module

Enabling videos in your Divi video module to start playing automatically can enhance both the site's design and user engagement. To ensure full compatibility with browser requirements, such as Chrome's autoplay policy, it's often necessary to start your videos muted...

Random Divi Posts