Skip to content

Accordion: how to have it collapsed by default #904

Closed Answered by crftwrk
chopinesque asked this question in Q&A
Discussion options

You must be logged in to vote

Class show on collapse means that collapse is shown. So, remove show class on collapse and set aria-expanded="true" to false in the button and collapse is collapsed.

See https://getbootstrap.com/docs/5.3/components/accordion/#example

<div id="accordionExample" class="accordion">
  <div class="accordion-item">
    <h2 class="accordion-header"><button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">HEADER</button></h2>
    <div id="collapseOne" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
      <div class="accordion-body">

        CONTENT

      </div>
    </div>
  </div

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by chopinesque
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants