
The Bootstrap example is a fine way to do this. You can see how this is done in Bootstrap 4's accordion example. Also, the markup and JavaScript above doesn't take into account there being multiple accordions on the page, and you would need to indicate this with id or data- attributes. Try pressing the 'Tab' key and notice that isn't highlighted, nor when you click on it, does it indicate that the accordion body is open. Written as-is, we are missing keyboard and screen reader accessibility. Then with some JavaScript/jQuery, when the title is clicked, we toggle the display of the : $('.collapse-title').click(function() )Īnd this works! Kinda. collapse-details to not appear when the page first loads. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. The setup here is simple: have one that is the clickable title and another which is the body of the accordion. There are a few different ways you could build this, but I recently learned that there's a way built right into HTML5! But first, let's take a look at the ways I (and probably you) have done this before.
#Html5 bootstrap builder code#
If you're a web developer, you've also probably had to code one of these, myself included.

Click the title again, and it closes back up.


Use the web for a short amount of time and you'll no doubt bump into an accordion, one of those collapsible elements that, when you click on its title, opens up to reveal more information.
