Snippets Accordion

Bootstrap 5 Accordion with Numbered Cards

A card-style accordion where one section is open at a time, with numbered headings and a highlighted active item. It answers five questions about React, including a JSX code sample.

Bootstrap 5 No jQuery Jul 2019 2.1K views

<section class="wdw-stage">
  <div class="container" style="max-width:820px">
    <div class="text-center mb-4">
      <span class="wdw-eyebrow mb-2">Learn the basics</span>
      <h2 class="wdw-heading display-5 mb-2">All about React</h2>
      <p class="wdw-muted mb-0">Five short answers on the library behind much of the modern web.</p>
    </div>
    <div class="accordion tidy-accordion" id="reactAccordion">
      <div class="accordion-item">
        <h3 class="accordion-header">
          <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#rx1" aria-expanded="true" aria-controls="rx1">
            <span class="tidy-num">01</span>What is React?
          </button>
        </h3>
        <div id="rx1" class="accordion-collapse collapse show" data-bs-parent="#reactAccordion">
          <div class="accordion-body">
            React is an open-source JavaScript library for building user interfaces. It lets developers create large web applications whose data changes over time without reloading the page, aiming for speed, simplicity and scalability. It handles only the view layer, so it combines well with other libraries.
          </div>
        </div>
      </div>
      <div class="accordion-item">
        <h3 class="accordion-header">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#rx2" aria-expanded="false" aria-controls="rx2">
            <span class="tidy-num">02</span>History
          </button>
        </h3>
        <div id="rx2" class="accordion-collapse collapse" data-bs-parent="#reactAccordion">
          <div class="accordion-body">
            React was created by Jordan Walke, a software engineer at Facebook. It first shipped in the Facebook newsfeed in 2011, reached Instagram in 2012 and was open-sourced at JSConf US in May 2013. React Native followed in 2015, bringing the same model to mobile.
          </div>
        </div>
      </div>
      <div class="accordion-item">
        <h3 class="accordion-header">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#rx3" aria-expanded="false" aria-controls="rx3">
            <span class="tidy-num">03</span>Unidirectional data flow
          </button>
        </h3>
        <div id="rx3" class="accordion-collapse collapse" data-bs-parent="#reactAccordion">
          <div class="accordion-body">
            Properties are immutable values passed down to a component. A component cannot change them directly, but it can receive callback functions that do. The promise is simple: properties flow down, actions flow up.
          </div>
        </div>
      </div>
      <div class="accordion-item">
        <h3 class="accordion-header">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#rx4" aria-expanded="false" aria-controls="rx4">
            <span class="tidy-num">04</span>Virtual DOM
          </button>
        </h3>
        <div id="rx4" class="accordion-collapse collapse" data-bs-parent="#reactAccordion">
          <div class="accordion-body">
            React keeps an in-memory copy of the interface, computes what changed and updates only those parts of the real DOM. You can write code as if the whole page re-renders on every change.
          </div>
        </div>
      </div>
      <div class="accordion-item">
        <h3 class="accordion-header">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#rx5" aria-expanded="false" aria-controls="rx5">
            <span class="tidy-num">05</span>JSX
          </button>
        </h3>
        <div id="rx5" class="accordion-collapse collapse" data-bs-parent="#reactAccordion">
          <div class="accordion-body">
            Components are usually written in JSX, a syntax extension that lets you write HTML-like tags inside JavaScript.
            <pre class="tidy-code mt-3 mb-0"><code>function Hello({ name }) {
  return <h1>Hello, {name}</h1>;
}</code></pre>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.