📖 Scenario: You are building a simple FAQ section for a website. You want to use Bootstrap's accordion component but with a flush style that removes the default outer borders for a cleaner look.
🎯 Goal: Build a Bootstrap accordion with the accordion-flush class that contains three collapsible items. Each item should have a header button that toggles its content panel.
📋 What You'll Learn
Use Bootstrap 5 accordion component
Apply the accordion-flush class to the accordion container
Create exactly three accordion items
Each accordion item must have a header with a button that toggles the content
Ensure the accordion is accessible with proper aria attributes
💡 Why This Matters
🌍 Real World
Accordions are commonly used on websites to organize content like FAQs, menus, or sections that expand and collapse to save space and improve user experience.
💼 Career
Knowing how to implement Bootstrap components like accordions is useful for front-end developers to quickly build interactive and accessible UI elements that work well on all devices.
Progress0 / 4 steps
1
Create the basic accordion container
Write the HTML code to create a div with id="faqAccordion" and the Bootstrap class accordion. This will be the container for the accordion items.
Bootsrap
Hint
Use a div with id="faqAccordion" and class accordion.
2
Add the flush style to the accordion container
Modify the div with id="faqAccordion" to add the Bootstrap class accordion-flush alongside accordion.
Bootsrap
Hint
Add the class accordion-flush next to accordion in the container div.
3
Add the first accordion item with header and collapse content
Inside the div with id="faqAccordion", add one accordion item. Use a div with class accordion-item. Inside it, add a header h2 with class accordion-header and id="flush-headingOne". Add a button inside the header with class accordion-button collapsed, type="button", data-bs-toggle="collapse", data-bs-target="#flush-collapseOne", aria-expanded="false", and aria-controls="flush-collapseOne". The button text should be "Accordion Item #1". Then add a div with id="flush-collapseOne", class accordion-collapse collapse, aria-labelledby="flush-headingOne", and data-bs-parent="#faqAccordion". Inside this div, add a div with class accordion-body containing the text "This is the first item's accordion body."
Bootsrap
Hint
Follow Bootstrap's accordion item structure carefully. Use the exact IDs and classes as specified.
4
Add the second and third accordion items
Add two more accordion items inside the div with id="faqAccordion". For the second item, use id="flush-headingTwo" for the header, button with data-bs-target="#flush-collapseTwo", and collapse div with id="flush-collapseTwo" and aria-labelledby="flush-headingTwo". The button text is "Accordion Item #2" and the body text is "This is the second item's accordion body." For the third item, use id="flush-headingThree", data-bs-target="#flush-collapseThree", id="flush-collapseThree", and aria-labelledby="flush-headingThree". The button text is "Accordion Item #3" and the body text is "This is the third item's accordion body." Keep the same classes and attributes as the first item for consistency.
Bootsrap
Hint
Copy the structure of the first accordion item and update the IDs and texts for the second and third items exactly as described.
Practice
(1/5)
1. What is the main visual difference when using the accordion-flush class in Bootstrap's accordion component?
easy
A. It removes the default background and borders between accordion items for a seamless look.
B. It adds extra padding inside each accordion item for better spacing.
C. It changes the accordion headers to use a different font style.
D. It makes the accordion items collapsible only on hover.
Solution
Step 1: Understand the accordion-flush class purpose
The accordion-flush class is designed to remove the default background color and borders between accordion items.
Step 2: Visual effect of accordion-flush
This creates a seamless, flush look where accordion items appear connected without spacing or borders.
Final Answer:
It removes the default background and borders between accordion items for a seamless look. -> Option A
A. Missing the base accordion class alongside accordion-flush.
B. Accordion items must have flush class individually.
C. Not including Bootstrap JavaScript file.
D. Using flush instead of accordion-flush class.
Solution
Step 1: Check the class names used
The code uses class='accordion flush', but the correct flush variant class is accordion-flush.
Step 2: Understand effect of incorrect class
Using flush alone does nothing; the flush style is not applied, so borders remain visible.
Final Answer:
Using flush instead of accordion-flush class. -> Option D
Quick Check:
Correct flush class is 'accordion-flush' not 'flush' [OK]
Hint: Use exact class 'accordion-flush' for flush style [OK]
Common Mistakes:
Typing 'flush' instead of 'accordion-flush'
Forgetting to include 'accordion' base class
Assuming JS affects border styles
5. You want to create a flush accordion with three items where only one item can be open at a time. Which of the following code snippets correctly implements this behavior?
hard
A.
<div class='accordion accordion-flush' id='accordionFlushExample'>
<div class='accordion-item'>
<h2 class='accordion-header' id='flush-headingOne'>
<button class='accordion-button collapsed' type='button' data-bs-toggle='collapse' data-bs-target='#flush-collapseOne' aria-expanded='false' aria-controls='flush-collapseOne'>Item 1</button>
</h2>
<div id='flush-collapseOne' class='accordion-collapse collapse' aria-labelledby='flush-headingOne' data-bs-parent='#accordionFlushExample'>
<div class='accordion-body'>Content 1</div>
</div>
</div>
<!-- Repeat for items 2 and 3 with unique IDs and same data-bs-parent -->
</div>