The Bootstrap Collapse component uses CSS transitions to animate the height property from 0 to the content's full height and vice versa. This creates a smooth sliding effect when showing or hiding content.
The correct attribute to trigger a collapse toggle in Bootstrap is data-toggle="collapse". This tells Bootstrap's JavaScript to listen for clicks and toggle the collapse.
<button class="btn btn-primary" data-toggle="collapse" data-target="#info">Toggle Info</button> <div id="info" class="collapse show"> <p>This is some collapsible content.</p> </div>
The collapse show classes mean the content is visible on page load. Clicking the button toggles the visibility with animation.
Bootstrap adds the show class to expanded collapse elements. So .collapse.show selects only those visible elements.
The aria-expanded attribute on the toggle button indicates whether the collapsible content is currently expanded (true) or collapsed (false), improving accessibility.