Make Divi Accordion Items Closeable

Written by Dan Mossop

Enabling closeable accordion items in your Divi layouts provides visitors with greater control over the content they view, allowing them to close open sections without automatically opening another. This can improve user experience by reducing clutter and helping users focus only on the information they wish to see. In this guide we show you how to set up your Divi Accordion module so that individual items can be closed independently.

Make Divi Accordion Items Closeable Using the Divi Booster Plugin

This method shows how to make the Divi Accordion module's items closeable by enabling the 'Closeable' toggle provided by the Divi Booster plugin. It is a straightforward solution that requires no coding and allows users to easily configure the closeable behavior directly from the module's design settings.

Enable the 'Closeable' Option in Accordion Settings

In your existing page or layout where you've added an Accordion module, open the Accordion module's settings. Head to the Design tab, then expand the Toggle section. Here, you'll see the Closeable option. Switch the 'Closeable' toggle to YES to allow users to close each accordion item independently—with no other item automatically opening in its place.

Styling the Close Icon

The close icon added by this feature 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: 

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:

/* Normal state */
.et_pb_accordion .et_pb_toggle_open .et_pb_toggle_title:before {
	color: grey !important;
}

/* Hover state */
.et_pb_accordion .et_pb_toggle_open .et_pb_toggle_title:hover:before {
	color: blue !important;
}

The example above will make the icon grey normally, changing to blue when hovered. 

Save and Publish Your Changes

After enabling the 'Closeable' setting, simply click the green checkmark to save the Accordion module settings. Then, use the Divi Builder's toolbar at the bottom of the page to publish your changes and exit the visual builder. Your changes are now live!

Test the Closeable Accordion Feature

View your page on the front-end. Click the title of any accordion item to close it. Notice that you can now close all accordion items, leaving the accordion fully collapsed if you wish.

(Optional) 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 Divi Accordion Module Items Closeable using jQuery and CSS in Theme Options

This method explains how to make items in the Divi Accordion module independently closeable by adding custom jQuery and CSS code in the Theme Options integration area. By following these steps, you gain more control over accordion behavior without needing third-party plugins, making it a flexible solution for customizing your site's interactivity directly from the Divi settings.

Add Custom jQuery and CSS in Divi Theme Options

Navigate to the Divi > Theme Options page in your WordPress dashboard, and go to the Integration tab. In the section labeled 'Add code to the of your blog,' paste in the following code. This script and style allow users to close open accordion items with a click.

<script>
jQuery(function($){
  $('.et_pb_toggle_title').click(function(){
    var $toggle = $(this).closest('.et_pb_toggle');
    if (!$toggle.hasClass('et_pb_accordion_toggling')) {
      var $accordion = $toggle.closest('.et_pb_accordion');
      if ($toggle.hasClass('et_pb_toggle_open')) {
        $accordion.addClass('et_pb_accordion_toggling');
        $toggle.find('.et_pb_toggle_content').slideToggle(700, function() { 
          $toggle.removeClass('et_pb_toggle_open').addClass('et_pb_toggle_close'); 

        });
      }
      setTimeout(function(){ 
        $accordion.removeClass('et_pb_accordion_toggling'); 
      }, 750);
    }
  });
});
</script>
<style>
.et_pb_accordion .et_pb_toggle_open .et_pb_toggle_title:before {
    display: block!important;
    content: "\e04f" !important;
}
</style>

Save Theme Option Changes

Once you have pasted in the code, click the Save Changes button at the top of the Theme Options page to apply your new settings.

Insert an Accordion Module and Publish

Add an Accordion module to your desired row using Divi Builder. You can style your accordion as usual—no changes are needed in the module settings to enable closeable functionality with this method. When you're finished, save your module and publish the page.

Test Your Closeable Accordion

On the front-end, test your accordion by clicking any accordion item’s title to open or close it. Thanks to your custom code, you (and your visitors) can now collapse all sections without having to keep any of them open.

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.

<script>
jQuery(function($){
	$('.et_pb_toggle_title').each(function(){
		var $title = $(this);
		var $closebar = $title.clone(true).addClass('db_pb_toggle_close2').html(' ');
		$title.closest('.et_pb_toggle').append($closebar);
	});
		
  	$('.db_pb_toggle_close2').click(function(){ // Listen for clicks on the close bar
    		var $toggle = $(this).closest('.et_pb_toggle');
    		var mainAreaOffset = $('#et-main-area').length ? $('#et-main-area').offset().top : 0;
    		$('html, body').animate({scrollTop: $toggle.offset().top - mainAreaOffset - 16}, 700); // Scroll considering the main area's top offset
  	});
});
</script>
<style>
	.et_pb_toggle_close .db_pb_toggle_close2 {
		display: none; 
	}
	.db_pb_toggle_close2 { 
		margin-top: 10px; 
		visibility: hidden;
	}
	.db_pb_toggle_close2:before {
		visibility: visible;
	}
</style>

Conclusion

Allowing visitors to close accordion items adds flexibility and improves navigation in your Divi layouts. You can achieve this easily with the Divi Booster plugin or by inserting a simple code snippet into your Theme Options. Enjoy a cleaner, more interactive accordion experience!

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

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.

Latest Posts

Set Custom CSS IDs for Individual Divi Accordion Items

Assigning unique CSS IDs to specific Divi Accordion items allows for precise control over styling, targeting, and linking within your page content. This ability is particularly useful when you want to apply custom designs or create anchor links to particular accordion...

Enable Swipe Navigation in the Divi Gallery Lightbox

Enabling swipe navigation in the Divi Gallery module's lightbox allows users to seamlessly browse through gallery images by swiping left or right, creating a more interactive and mobile-friendly experience. This functionality can significantly improve user engagement...

Disable Slide-In Animation for Divi Gallery Grid Images

Control how images appear in your Divi Gallery module by toggling the slide-in animation effect for grid layouts. Disabling the slide-in animation allows gallery images to load instantly and appear statically, providing a faster and distraction-free browsing...

Control Image Count Display in Divi Gallery Lightbox

Displaying or hiding the image count in the Divi Gallery module’s lightbox can help customize the user experience, depending on whether you want to give visitors an indication of gallery progress or prefer a cleaner, distraction-free view. The ability to toggle this...

Hide Gallery Image Titles in the Divi Lightbox Overlay

Displaying image titles in the lightbox overlay of the Divi Gallery module can sometimes be distracting or unnecessary, depending on your website’s design and user experience goals. Hiding these titles creates a cleaner and more focused viewing experience for visitors...

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 *.