Make Divi Accordion Items Closeable in Divi 5 & Divi 4

Written by Dan Mossop

YouTube video

By default, Divi Accordion modules keep one toggle open. That means visitors can open another item, but they cannot simply close the currently open item and leave the whole accordion collapsed.

In this guide – updated for Divi 5 – I’ll show you how to make Divi Accordion items closeable in Divi 5 and Divi 4, so visitors can open and close each accordion section independently.

This can make FAQ sections, product details, documentation, and long content panels cleaner and easier to browse.

Quick answer:

To make a single Divi Accordion module closeable, enable the Closeable option added by Divi Booster at Accordion Settings → Design → Toggle.

To make all Accordion modules across your site closeable, enable the global Make accordions closable option in Divi Booster under Modules → Accordion.

Either option lets visitors close the currently open accordion item and leave the accordion fully collapsed.

If you prefer not to use a plugin, you can also use the jQuery and CSS snippet later in this guide, though custom code may need updating if Divi changes its accordion markup or behavior.

In this guide, I’ll cover three ways to make Divi Accordion items closeable:

1. Make individual Accordion modules closeable using Divi Booster.
2. Make all Accordion modules closeable site-wide using Divi Booster.
3. Make Accordion modules closeable manually using jQuery and CSS.

Want the easiest option? Divi Booster adds the Closeable setting directly to the Accordion module, so you can enable it from the Divi interface without adding or maintaining code.

Make Individual Divi Accordion Modules Closeable Using Divi Booster

Use this method when you want to make one or more specific Accordion modules closeable, while leaving other accordions on your site unchanged.

Divi Booster adds a Closeable setting to individual Accordion modules, allowing that module’s items to be opened and closed independently from the module settings.

If you already have Divi Booster installed, follow the steps below. If not, you can get Divi Booster here and enable closeable accordions without adding custom code.

Enable the 'Closeable' Option in Accordion Settings

In the page or layout containing your 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 On to allow users to close each accordion item independently – with no other item automatically opening in its place.

Style the Close Icon in the Module Settings

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: 

Save and Publish Your Changes

After making your changes in the accordion module, save your changes. When you are ready to do so, publish your page so that your changes will be applied to the live view of the page.

Test the Closeable Accordion Feature

View your accordion on the front end. You should now see that a "close" icon has been added to open toggles. Clicking on the icon or title of an open accordion toggle will now close that toggle, even if all other toggles are already closed.

(Optional) Start the Accordion Fully Closed

Closeable accordions are often used together with an all-closed initial state, especially for FAQ sections. Divi Booster also adds an Initial State option for Accordion modules, letting you choose Default, All Closed, or All Open.

See the full guide: How to Start a Divi Accordion Module All Closed

Make All Divi Accordion Modules Closeable Using Divi Booster

Use this method if you want closeable accordion behavior across your whole site, rather than enabling it one module at a time.

Divi Booster includes a global Make accordions closable option that applies the closeable behavior to Accordion modules site-wide. This affects Accordion modules across your site, while still allowing each module’s normal design settings to control its appearance.

This is useful if you use accordions throughout your site for FAQs, product information, documentation, support pages, or other expandable content.

Enable the 'Make accordions closable' Option in Divi Booster

In your WordPress dashboard, go to Divi → Divi Booster → Modules → Accordion. Enable the Make accordions closable option.

Once enabled, open accordion toggles will display a close icon and can be collapsed without forcing another toggle to open.

Save Your Changes

Click Save Changes at the top of the Divi Booster settings page to apply the setting.

Test Your Site-Wide Closeable Accordions

View one of your Accordion modules on the front end. Open a toggle, then click the title or close icon again. The toggle should close, even if no other accordion item is opened.

Style the Close Icon Globally

The close icon inherits the styling of Divi’s built-in open icon. For individual Accordion modules, you can style the icon using the module’s normal icon design settings.

If you want to apply styling globally across your site, you can use CSS such as:

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

(Optional) Start All Accordions Fully Closed

Closeable accordions are often used together with an all-closed initial state, especially for FAQ sections. Divi Booster includes a global 'Make accordions start fully closed by default' option that can be applied to all accordions.

See the full guide: How to Start a Divi Accordion Module All Closed

Make Divi Accordion Modules Closeable Manually Using jQuery and CSS

If you don’t want to use a plugin, you can make Divi Accordion items closeable with custom jQuery and CSS. This is useful for one-off customizations, but because it relies on Divi’s front-end markup and animation classes, you may need to revisit the code after future Divi updates.

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 <head> of your blog, paste the following code. This script and style allow users to close open accordion items with a click.

When added in Divi Theme Options, this code applies to Accordion modules across your site. For a single page only, you can instead place the code in a Code module on that page.

For a no-code version, use one of the Divi Booster methods above: the module-level setting for a single accordion, or the global setting for all accordions.

Otherwise, paste the following code:

<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 the accordion as usual – no module setting changes are needed to enable closeable functionality with this method. When you're finished, save your changes.

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, your visitors can close any sections they are finished reading.

(Optional) Add a Second Close Icon to Long Accordion Toggles

If you have very long accordion content, visitors may need to scroll back to the top of the toggle to close it. In that case, you can add a second close icon at the bottom of each open toggle using the additional code below.

Use this in addition to the main jQuery and CSS code above:

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

Customize the Accordion Further

Once your accordion items can be closed, you may also want to make the accordion start with all items closed, or add a button that opens and closes every toggle at once.

See also:

Conclusion

Making Divi Accordion items closeable gives visitors more control over what stays open on the page, which is especially useful for FAQs, product details and long information sections.

For the simplest setup, use Divi Booster to enable closeable accordions from the module settings or apply the behavior site-wide from the Divi Booster settings page. If you prefer a manual approach, the jQuery and CSS method above can also be used, though it may require maintenance after future Divi updates.

Make Divi Accordions Closeable Without Code

Want to make Divi Accordion items closeable without adding custom jQuery? Divi Booster adds closeable accordion options directly to Divi, including a module-level Closeable setting and a global option for applying the behavior across your site. It also includes related accordion settings, such as starting accordions fully closed, making it a simple way to improve FAQ sections, product information panels and other expandable content.

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, 

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

131 Comments

  1. It took some help but now I have it working with a different icon for the close!

    #page-container .et_pb_toggle_open .et_pb_toggle_title:before {
    display: block !important;
    content: "\42"!important;
    }

    Reply
    • Nice one, Sheila! I'm glad you were able to get it working and thanks for sharing! :)

      Reply
  2. I must say. I purchased lifelong DIVI BOOSTER package in 2018. I forgot about it. I really needed to find a solutions for a large site I am working on and when I Googled for the solution, I found this page. I checked my files and found my login to your website. All the details were there and it saved my day!
    So, I just wanted to say thank you for being here for over 6 years! I just think that is really cool. What great value!

    Reply
    • Clayton, you just made my day. Thank you! :)

      Reply
  3. Hello, I have a question, I have added the code but on Safari it doesn't work, do you know why?

    Reply
    • Hi Bryan, sorry I'm only just responding now. I'm not sure yet why it's not working on Safari for you. I just checked on my test site and it seems to be working correctly on Safari. If you haven't already, try clearing the browser cache in Safari. If that doesn't help, are you able to share a link to the page you're working on so that I can check it out for you? Thanks!

      Reply
  4. Thank you! Amazing post!

    Reply
    • You're welcome, Renzo!

      Reply
  5. Hey there! I've followed the instructions and the icon appears, but it doesn't close the accordion module. Any ideas why this might be the case? Thank you!

    Reply
    • Hey Gillian! Thanks for reaching out. It sounds like an issue with the jQuery code – either it isn't working on your site or something is blocking it from running. Are you able to share the URL of the page where you've set up the accordion so I can take a closer look? In the meantime, try clearing your caches just to make sure you're not seeing an older version the page. Thanks! Dan

      Reply
  6. Thank you.This one solve my problem.

    Reply
    • Great! Glad it helped SuB HerO :)

      Reply
  7. Thank you very much! It's great!

    Reply
    • You’re very welcome, Mikhail!

      Reply
  8. how can i style the icon you added to the toggle tab when closed?

    Reply
    • Hey Christina, I've just added a section to the post on styling the close icon. The process is the same, regardless of which method you used to make the accordion closeable. If you need any help getting it to look how you want, just let me know (with a link to the page you're working on, if possible). Thanks!

      Reply
  9. I have added the code as instructed but my accordions still done close. I know the code is working but this line never gets true if ($toggle.hasClass('et_pb_toggle_open')) {

    As other people have this working I am wondering what I am doing wrong.

    Reply
    • Hey Ralf, the code is still working for me in the latest version of Divi, so I'm not sure yet why it's not working for you. Is there any chance you're able to share a link so that I can take a look?

      The 'et_pb_toggle_open' class is applied by Divi to any open toggles in the accordion, so that line should in theory be true whenever the clicked accordion toggle is initially open…

      Reply
    • I just implemented this solution, but in a slightly different way. Rather than putting the javascript in the Theme Options > Integration > Head of my site, I put the script in a Code Module BELOW the Accordion Module, right on the page. I did this so that the script only loaded on the page where I needed it.

      The solution is working as expected – thank you for sharing this solution!!

      Is there a way to force the accordion to be all closed by default?

      Reply
      • You're welcome, Jono. The code module is a great way to load Javascript on a single page – good to hear the code works in this configuration. Thanks! This post describes how to start accordions closed by default:

        https://divibooster.com/make-divi-accordions-closed-by-default/

        You should be able to place that in the same code module (or an additional one), if you wish. Hope it helps.

        Reply
  10. I try with with both code you mentioned, and three of your CSS working together, the site is working fine now!

    Thank you very very much for your share.

    however, do you know how to add ICON to Accordion?

    Reply
  11. How can I change the icon in the open-state? It's still the same when I open it what doesn't make any sense as I want a "-" sign to close and a "+" sign to open. Please help

    Reply
    • Hey Carola, both the Divi Booster feature and the manual method (if you follow the optional step 2) should give a "-" sign for closing the accordion tabs. But if it isn't working for you, is there any chance you're able through a link to the page you're working on so that I can take a look for you? Cheers!

      Reply
        • Hey Maurice, it looks like Divi's own styles are taking priority. I've updated the CSS in the post to be slightly more specific, which means it should override Divi's own styles and get the (-) icon showing. Note that the issue isn't one of positioning as that site suggests. The version of the code posted there also doesn't work as-is because the quotation marks are being modified from straight to curly quotes. Hope that helps!

          Reply
          • That worked great! Thank you very much

          • Great! You’re very welcome, Maurice!

    • Hey Stephanie, I can't see the CSS for adding the close icon being applied to your site. If you haven't added it yet, here it is (same as in the post):

      .et_pb_toggle_open .et_pb_toggle_title:before {
      	display: block !important;
      	content: "\e04f";
      }
      

      Try adding it in the "Divi > Theme Options > General > Custom CSS" box to see if that works.

      If you've already added it / it still doesn't show, I can see you've got some form of caching on your site. Try clearing your caches and refreshing the page – hopefully that will get it showing up.

      Let me know if that doesn't fix it. Thanks!

      P.S. I tested the CSS above against your site and it made the close icon show correctly, so once it's getting added to the live page you should be good to go.

      Reply
      • Hello, Dan. I have exactly same problem with Stephanie Parr, the close icon works fine, but its not show up on the page…
        By the way, what you shared is very very useful, thank you.

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

Get this feature

This feature is available in the following plugins:

Divi Booster

About Divi Booster

Compatible with

Divi 5

Divi 4

News