What is an Accordion component in web development?
An Accordion is a UI element that lets users expand and collapse sections to show or hide content. It helps organize information in a small space.
Click to reveal answer
beginner
Which Bootstrap class is used to create the main container for an Accordion?
The class .accordion is used as the main container for grouping accordion items in Bootstrap.
Click to reveal answer
intermediate
How do you make an Accordion item collapsible in Bootstrap?
Use the data-bs-toggle="collapse" attribute on the button or link that controls the item, and connect it to a .collapse element with a unique ID.
Click to reveal answer
intermediate
What role does the aria-expanded attribute play in an Accordion?
It tells screen readers if the Accordion section is open (true) or closed (false), improving accessibility.
Click to reveal answer
intermediate
How can you ensure only one Accordion item is open at a time in Bootstrap?
Set the same data-bs-parent attribute on each collapsible content element, pointing to the Accordion container. This makes them behave like an exclusive group.
Click to reveal answer
Which Bootstrap class wraps all Accordion items?
A.collapse
B.accordion
C.accordion-item
D.accordion-header
✗ Incorrect
The .accordion class is the main container for all Accordion items.
What attribute do you add to a button to toggle Accordion content?
Adata-bs-toggle="collapse"
Bdata-toggle="accordion"
Caria-hidden="true"
Ddata-bs-target="accordion"
✗ Incorrect
Use data-bs-toggle="collapse" to make the button toggle the collapsible content.
How do you link a button to the content it controls in Bootstrap Accordion?
AUsing href or data-bs-target with the content's ID
BUsing class names only
CUsing aria-label only
DNo linking is needed
✗ Incorrect
The button uses href="#id" or data-bs-target="#id" to connect to the collapsible content.
What does setting data-bs-parent do in an Accordion?
AChanges the Accordion color
BAllows multiple items open simultaneously
CDisables the Accordion
DMakes only one item open at a time
✗ Incorrect
It ensures only one Accordion item is open by linking all collapsible items to the same parent.
Which attribute improves Accordion accessibility for screen readers?
Aid
Bdata-bs-toggle
Caria-expanded
Dclass
✗ Incorrect
aria-expanded tells screen readers if the section is open or closed.
Explain how to build a basic Accordion component using Bootstrap.
Think about the structure and attributes needed for toggling.
You got /6 concepts.
Describe how accessibility is handled in a Bootstrap Accordion.
Focus on attributes that help screen readers understand the Accordion state.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of the Accordion component in Bootstrap?
easy
A. To create a navigation bar with dropdown menus
B. To show and hide sections of content by expanding or collapsing them
C. To display images in a sliding carousel
D. To style buttons with different colors
Solution
Step 1: Understand Accordion functionality
The Accordion component is designed to toggle visibility of content sections by expanding or collapsing them.
Step 2: Compare with other Bootstrap components
Navigation bars, carousels, and buttons serve different purposes unrelated to content toggling.
Final Answer:
To show and hide sections of content by expanding or collapsing them -> Option B
Quick Check:
Accordion = toggle content visibility [OK]
Hint: Accordion toggles content sections open or closed [OK]
Common Mistakes:
Confusing Accordion with navigation menus
Thinking Accordion is for image sliders
Assuming Accordion styles buttons
2. Which of the following is the correct HTML structure to start an Accordion in Bootstrap 5?
easy
A. <div class='accordion' id='myAccordion'>
B. <accordion id='myAccordion'>
C. <div class='accordion-item'>
D. <section class='accordion-collapse'>
Solution
Step 1: Identify the container element for Accordion
The Accordion container uses a div with class accordion and an ID for reference.
Step 2: Check Bootstrap 5 syntax
Bootstrap 5 requires div.accordion as the wrapper, not accordion tag or other classes like accordion-item or accordion-collapse alone.
Final Answer:
<div class='accordion' id='myAccordion'> -> Option A
Quick Check:
Accordion container = div.accordion [OK]
Hint: Accordion always starts with div.accordion container [OK]
Common Mistakes:
Using a non-existent <accordion> tag
Starting with accordion-item instead of accordion container
Confusing collapse section with container
3. Given this Accordion item code snippet, what will happen when the button is clicked?
A. The accordion-collapse div is missing the collapse class
B. The button should not have aria-expanded attribute
C. The data-bs-parent attribute should be on the button, not the collapse div
D. The accordion container is missing an ID
Solution
Step 1: Check classes on collapsible content
The collapsible div must have class collapse to enable Bootstrap's collapse behavior.
Step 2: Verify other attributes
The aria-expanded attribute on the button is correct and data-bs-parent belongs on the collapse div. The container has an ID.
Final Answer:
The accordion-collapse div is missing the collapse class -> Option A
Quick Check:
collapse class missing = no toggle [OK]
Hint: Always add 'collapse' class to collapsible content div [OK]
Common Mistakes:
Forgetting the 'collapse' class on content div
Misplacing data-bs-parent attribute
Removing aria-expanded attribute
5. You want to create an Accordion where only one section can be open at a time, and the first section is open by default. Which combination of attributes and classes achieves this behavior correctly?
hard
A. Add data-bs-single='true' to buttons and expanded attribute on first button
B. Add data-bs-toggle='accordion' to buttons and active class to first button
C. Use data-bs-multiple='false' on accordion container and open class on first item
D. Add data-bs-parent to each collapse div and add show class to the first collapse div