0
0
Bootsrapmarkup~10 mins

Accordion component in Bootsrap - Browser Rendering Trace

Choose your learning style9 modes available
Render Flow - Accordion component
Read HTML structure
Create accordion container
Create accordion items
Add headers with buttons
Add collapsible content sections
Apply Bootstrap JS for toggle behavior
Listen for click events
Toggle collapse state
Repaint updated visibility
The browser reads the HTML structure of the accordion, builds the container and items, then Bootstrap's JavaScript listens for clicks on headers to toggle the visibility of content sections, causing the browser to repaint the visible parts.
Render Steps - 5 Steps
Code Added:<div class="accordion" id="accordionExample"> ... </div>
Before
[Empty page]
After
[Accordion container box]
  (No visible content yet)
The accordion container is created but no visible content is shown yet because items are not added.
🔧 Browser Action:Creates DOM node for accordion container
Code Sample
This code creates a single accordion item with a header button that toggles the visibility of its content area.
Bootsrap
<div class="accordion" id="accordionExample">
  <div class="accordion-item">
    <h2 class="accordion-header" id="headingOne">
      <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
        Accordion Item #1
      </button>
    </h2>
    <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
      <div class="accordion-body">
        Content for item 1.
      </div>
    </div>
  </div>
</div>
Render Quiz - 3 Questions
Test your understanding
After applying step 4, what do you see in the accordion?
AOnly the header is visible, content is hidden
BThe content area is visible below the header
CThe accordion container is empty
DMultiple accordion items are open
Common Confusions - 3 Topics
Why does the content not show when I click the header button?
The Bootstrap JavaScript is required to toggle the 'show' class on the content. Without including Bootstrap's JS, clicking does nothing visually (see render_step 5).
💡 Always include Bootstrap JS for interactive components.
Why is only one accordion item open at a time?
The 'data-bs-parent' attribute on the collapse content tells Bootstrap to close other items when one opens, creating an exclusive open behavior (accordion effect).
💡 Use 'data-bs-parent' to link items for exclusive toggling.
Why does the accordion button have an arrow icon that changes direction?
Bootstrap adds CSS styles and transitions to the button to show an arrow that rotates when the content is expanded or collapsed, giving visual feedback (part of accordion-button class).
💡 Button styles reflect toggle state visually.
Property Reference
PropertyValue AppliedEffect on AccordionCommon Use
class="accordion"Container classDefines accordion container styling and behaviorWrap all accordion items
class="accordion-item"Item containerWraps each accordion sectionGroup header and content
class="accordion-header"Header wrapperContains the clickable buttonDefines header area
class="accordion-button"Button styleClickable element that toggles contentUser interaction
class="accordion-collapse collapse"Collapse behaviorContent hidden by defaultHide content initially
class="show"Visibility toggleMakes content visibleShow expanded content
data-bs-toggle="collapse"Bootstrap JS hookEnables toggle on clickConnect button to collapse
data-bs-target="#id"Target contentSpecifies which content to toggleLink button to content
aria-expandedtrue/falseAccessibility state of toggleScreen reader info
aria-controls#idAccessibility control linkScreen reader info
Concept Snapshot
Accordion component uses a container with multiple items. Each item has a header button and a collapsible content section. Bootstrap JS toggles the 'show' class to show/hide content. Use data-bs-toggle and data-bs-target to link button and content. 'aria-expanded' and 'aria-controls' improve accessibility. 'data-bs-parent' makes only one item open at a time.