What is the purpose of the Bootstrap Collapse component?
The Collapse component allows you to show or hide content with a smooth sliding animation, helping to save space and organize information on a webpage.
Click to reveal answer
beginner
Which HTML attribute is used to toggle the Collapse component in Bootstrap?
The data-bs-toggle="collapse" attribute is used on a button or link to toggle the visibility of the target content.
Click to reveal answer
beginner
How do you link a button to the content it controls in a Bootstrap Collapse?
Use the data-bs-target attribute on the button with the CSS selector (like an ID) of the collapsible content, for example data-bs-target="#myCollapse".
Click to reveal answer
beginner
What class must be added to the content element to make it collapsible in Bootstrap?
The content element must have the class <code>collapse</code> to be collapsible. Adding <code>show</code> class makes it visible by default.
Click to reveal answer
intermediate
How can you make multiple Collapse components work as an accordion in Bootstrap?
Wrap the collapsible items in a parent element with id and add data-bs-parent="#parentID" to each collapse content. This makes only one item open at a time.
Click to reveal answer
Which attribute do you add to a button to toggle a Bootstrap Collapse?
Adata-bs-target="collapse"
Bdata-toggle="dropdown"
Cdata-bs-toggle="collapse"
Ddata-collapse="toggle"
✗ Incorrect
The correct attribute to toggle a collapse is data-bs-toggle="collapse".
What class should the collapsible content have in Bootstrap?
Acollapse-toggle
Bcollapsible
Ctoggle-collapse
Dcollapse
✗ Incorrect
The content must have the collapse class to be collapsible.
How do you make a Collapse component visible by default?
AAdd the class <code>show</code> to the collapse content
BAdd <code>data-visible="true"</code>
CAdd <code>visible</code> attribute
DAdd <code>active</code> class to the button
✗ Incorrect
Adding the show class to the collapse content makes it visible initially.
What does the data-bs-parent attribute do in a Collapse accordion?
AMakes the collapse content draggable
BEnsures only one collapse item is open at a time
CLinks the collapse to a button
DChanges the collapse animation speed
✗ Incorrect
data-bs-parent groups collapses so only one can be open, creating an accordion effect.
Which Bootstrap version introduced the data-bs-toggle attribute naming?
ABootstrap 5
BBootstrap 3
CBootstrap 4
DBootstrap 2
✗ Incorrect
Bootstrap 5 uses the data-bs- prefix for its JavaScript data attributes.
Explain how to create a simple Collapse component in Bootstrap that toggles content visibility when a button is clicked.
Think about the button attributes and the classes needed on the content.
You got /4 concepts.
Describe how to set up multiple Collapse components so they behave like an accordion, allowing only one open section at a time.
Focus on the data-bs-parent attribute and its effect.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the Bootstrap Collapse component?
easy
A. To hide or show content smoothly when a user clicks a control
B. To create a fixed navigation bar at the top of the page
C. To add animations to images on hover
D. To validate form inputs automatically
Solution
Step 1: Understand the Collapse component function
The Collapse component is designed to toggle visibility of content smoothly, usually triggered by user actions like clicks.
Step 2: Compare options with the component's purpose
Only To hide or show content smoothly when a user clicks a control describes hiding or showing content smoothly, which matches the Collapse component's role.
Final Answer:
To hide or show content smoothly when a user clicks a control -> Option A
Quick Check:
Collapse toggles content visibility = B [OK]
Hint: Collapse means hide/show content smoothly on click [OK]
Common Mistakes:
Confusing Collapse with navigation or animation components
Thinking Collapse validates forms
Assuming Collapse is for styling images
2. Which attribute is required on a button to toggle a Bootstrap Collapse element?
easy
A. data-target="collapse"
B. data-toggle="collapse"
C. data-bs-toggle="collapse"
D. data-bs-target="collapse"
Solution
Step 1: Identify the correct Bootstrap 5 attribute for toggling Collapse
Bootstrap 5 uses the prefix data-bs- for its JavaScript plugins, so the toggle attribute is data-bs-toggle="collapse".
Step 2: Eliminate outdated or incorrect attributes
Options A and B use syntax without bs prefix (Bootstrap 4 or earlier). data-bs-target="collapse"'s data-bs-target="collapse" specifies the target element, not the toggle action.
Final Answer:
data-bs-toggle="collapse" -> Option C
Quick Check:
Toggle attribute in Bootstrap 5 = data-bs-toggle="collapse" [OK]
Hint: Use data-bs-toggle="collapse" for toggling in Bootstrap 5 [OK]
Common Mistakes:
Using data-toggle instead of data-bs-toggle
Confusing data-bs-target with toggle attribute
Omitting the data-bs prefix
3. What will happen when the button below is clicked?
A. The div has a typo in the class name; it should be "collapse"
B. The button is missing the data-bs-toggle attribute
C. The div id does not match the data-bs-target
D. The button should use data-toggle instead of data-bs-toggle
Solution
Step 1: Check the button attributes
The button correctly uses data-bs-toggle="collapse" and targets #panel.
Step 2: Inspect the div class and id
The div has id "panel" matching the target, but the class is "collaps" instead of "collapse". This typo prevents the collapse behavior.
Final Answer:
The div has a typo in the class name; it should be "collapse" -> Option A
Quick Check:
Class must be "collapse" for Bootstrap to work [OK]
Hint: Check class spelling: must be "collapse" not "collaps" [OK]
Common Mistakes:
Misspelling the collapse class
Confusing data-bs-toggle with data-toggle
Mismatching id and data-bs-target
5. You want to create an accordion with two sections using Bootstrap Collapse. Which code snippet correctly ensures only one section is open at a time?