Expandable content is used in FAQs, menus, and dashboards to keep pages clean and easy to navigate.
💼 Career
Knowing how to implement expandable content with Bootstrap is useful for front-end web developers building user-friendly interfaces.
Progress0 / 4 steps
1
Create the FAQ questions list
Create a div with class accordion and inside it add three div elements with class accordion-item. Each item should have a header with a button containing the question text: What is Bootstrap?, How does collapse work?, and Why use expandable content?.
Bootsrap
Hint
Use Bootstrap's accordion structure with accordion-item, accordion-header, and a button with data-bs-toggle="collapse".
2
Add the collapsible answer sections
Below each question button, add a div with class accordion-collapse collapse and an id matching the button's data-bs-target attribute. Inside each, add a div with class accordion-body containing the answer text: Bootstrap is a CSS framework., Collapse toggles visibility of content., and Expandable content saves space on the page. respectively.
Bootsrap
Hint
Each answer should be inside a div with accordion-collapse collapse classes and an id matching the button's data-bs-target.
3
Set the first answer to be expanded by default
Modify the first answer's collapse div to have the class accordion-collapse collapse show so it is visible when the page loads. Also set the first button's aria-expanded attribute to true.
Bootsrap
Hint
Add the show class to the first collapse div and set the first button's aria-expanded to true.
4
Add Bootstrap CSS and JS links
Add the Bootstrap 5 CSS link inside the <head> and the Bootstrap 5 JavaScript bundle script before the closing </body> tag. Use the official CDN URLs: CSS https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css and JS https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js. Wrap the accordion inside a <main> element with class="container my-4". Also add the basic HTML5 document structure with lang="en", charset="UTF-8", and viewport meta tag.
Bootsrap
Hint
Include the Bootstrap CSS link in the <head> and the JS bundle script before </body>. Wrap the accordion in a <main> with container and margin classes.
Practice
(1/5)
1. Why is expandable content useful in web design using Bootstrap?
easy
A. It increases the font size of all text on the page.
B. It automatically changes the website's color scheme.
C. It hides extra details until the user wants to see them, saving space.
D. It disables all images to speed up loading.
Solution
Step 1: Understand the purpose of expandable content
Expandable content hides parts of the page that are not immediately needed, making the page look cleaner.
Step 2: Connect to Bootstrap's feature
Bootstrap provides easy ways to create these expandable sections, so users can click to see more details only if they want.
Final Answer:
It hides extra details until the user wants to see them, saving space. -> Option C
Quick Check:
Expandable content = saves space by hiding details [OK]
Hint: Expandable content hides details to save space [OK]
Common Mistakes:
Thinking expandable content changes colors
Confusing expandable content with font size changes
Believing it disables images
2. Which Bootstrap class is used to create a collapsible (expandable) content section?
easy
A. .collapse
B. .hidden-section
C. .expandable-content
D. .btn-expand
Solution
Step 1: Recall Bootstrap's class for collapsible content
Bootstrap uses the class .collapse to hide or show content when toggled.
Step 2: Verify other options
Other classes like .btn-expand, .expandable-content, and .hidden-section are not standard Bootstrap classes for this purpose.
Final Answer:
.collapse -> Option A
Quick Check:
Bootstrap collapsible class = .collapse [OK]
Hint: Remember: Bootstrap uses .collapse for expandable content [OK]
Common Mistakes:
Using non-existent classes like .btn-expand
Confusing with .hidden-section which is not Bootstrap standard
Assuming .expandable-content is a Bootstrap class
3. What will happen when the button is clicked in this Bootstrap code?
A. The button uses incorrect data attribute names for Bootstrap 5.
B. The div should not have an id attribute.
C. The button must have class .collapse instead of .btn-primary.
D. The div should be a <span> instead of a <div>.
Solution
Step 1: Check Bootstrap 5 data attribute syntax
Bootstrap 5 requires data attributes to start with data-bs-, so data-toggle and data-target are outdated.
Step 2: Confirm correct attributes
The correct attributes are data-bs-toggle="collapse" and data-bs-target="#details".
Final Answer:
The button uses incorrect data attribute names for Bootstrap 5. -> Option A
Quick Check:
Bootstrap 5 uses data-bs-toggle and data-bs-target [OK]
Hint: Use data-bs-toggle and data-bs-target in Bootstrap 5 [OK]
Common Mistakes:
Using old data-toggle instead of data-bs-toggle
Removing id from target div
Changing button class incorrectly
Changing div to span unnecessarily
5. You want to show a FAQ section where each question expands to show the answer without cluttering the page. Which Bootstrap approach best saves space and keeps the page user-friendly?
hard
A. Show all answers by default without any collapsible sections.
B. Use multiple .collapse sections with buttons toggling each answer individually.
C. Use large images instead of text to explain answers.
D. Hide all answers permanently and never allow expansion.
Solution
Step 1: Understand the goal of saving space and user-friendliness
Showing all answers at once can clutter the page, while hiding them permanently is not helpful.
Step 2: Evaluate Bootstrap's collapsible sections
Using multiple .collapse sections with toggle buttons lets users expand only the answers they want to read, keeping the page clean.
Final Answer:
Use multiple .collapse sections with buttons toggling each answer individually. -> Option B
Quick Check:
Expandable FAQ with .collapse = saves space and user-friendly [OK]
Hint: Use .collapse toggles for each FAQ answer [OK]
Common Mistakes:
Showing all answers by default causing clutter
Using images instead of text for answers
Hiding answers permanently without toggle
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.