Recall & Review
beginner Click to reveal answer
What is a button group in Bootstrap?
A button group in Bootstrap is a way to group multiple buttons together on a single line, making them look connected and organized.
beginner Click to reveal answer
Which Bootstrap class is used to create a button group container?The class
.btn-group is used to wrap buttons and create a button group.intermediate Click to reveal answer
How do you make a vertical button group in Bootstrap?
Add the class
.btn-group-vertical to the container instead of .btn-group to stack buttons vertically.intermediate Click to reveal answer
What role does the
aria-label attribute play in button groups?It improves accessibility by describing the group of buttons to screen readers, helping users understand the purpose of the group.
intermediate Click to reveal answer
How can you add spacing between buttons inside a button group?
Button groups remove spacing by default to connect buttons. To add space, you can use margin utilities like
me-2 on buttons or avoid grouping them.Which class creates a horizontal button group in Bootstrap?
✗ Incorrect
The class .btn-group creates a horizontal button group. .btn-group-vertical stacks buttons vertically.
What is the purpose of using
aria-label on a button group?✗ Incorrect
aria-label helps screen readers understand the purpose of the button group, improving accessibility.How do you create a vertical stack of buttons in Bootstrap?
✗ Incorrect
Bootstrap provides the .btn-group-vertical class to stack buttons vertically.
If you want buttons in a group to have space between them, what should you do?
✗ Incorrect
Button groups connect buttons tightly by default. Adding margin classes like me-2 adds space between buttons.
Which HTML element is recommended to wrap buttons in a Bootstrap button group?
✗ Incorrect
A
with the .btn-group class is commonly used to wrap buttons in a group.
Explain how to create a horizontal and a vertical button group in Bootstrap. Include accessibility considerations.
Think about the container classes and how screen readers understand groups.
You got /4 concepts.
Describe how you can add spacing between buttons inside a Bootstrap button group and why you might want to do that.
Consider Bootstrap's default button group behavior and margin utilities.
You got /4 concepts.
Practice
1. What is the main purpose of using the
btn-group class in Bootstrap?easy
Solution
Step 1: Understand the role of
Thebtn-groupbtn-groupclass is designed to place buttons next to each other horizontally, making them appear as one group.Step 2: Compare with other options
Changing colors, adding icons, or dropdowns require different classes or components, notbtn-group.Final Answer:
To group multiple buttons side by side as a single unit -> Option AQuick Check:
Button groups = group buttons side by side [OK]
Hint: Remember: btn-group means buttons together horizontally [OK]
Common Mistakes:
- Confusing btn-group with button color classes
- Thinking btn-group creates dropdowns
- Assuming btn-group adds icons automatically
2. Which of the following is the correct syntax to create a horizontal button group with three buttons labeled 'One', 'Two', and 'Three'?
easy
Solution
Step 1: Check the container class and role
The correct class for horizontal grouping isbtn-groupwithrole='group'for accessibility.Step 2: Verify button elements and labels
Buttons inside should havebtnand style classes likebtn-primary. The role must be 'group', not 'button'.Final Answer:
Correct horizontal button group with role='group' -> Option BQuick Check:
btn-group + role='group' = horizontal group [OK]
Hint: Use role='group' with btn-group for horizontal groups [OK]
Common Mistakes:
- Using btn-group-vertical for horizontal groups
- Setting role='button' instead of role='group'
- Missing role attribute for accessibility
3. What will be the visual result of this code snippet?
<div class='btn-group btn-group-lg' role='group' aria-label='Large button group'> <button type='button' class='btn btn-secondary'>Left</button> <button type='button' class='btn btn-secondary'>Middle</button> <button type='button' class='btn btn-secondary'>Right</button> </div>
medium
Solution
Step 1: Analyze the classes used
Thebtn-groupclass groups buttons horizontally. Thebtn-group-lgclass makes buttons larger in size.Step 2: Understand the layout effect
Buttons inside will appear side by side horizontally, not stacked vertically, and will be large due tobtn-group-lg.Final Answer:
Three large buttons aligned horizontally side by side -> Option DQuick Check:
btn-group + btn-group-lg = large horizontal buttons [OK]
Hint: btn-group-lg means bigger horizontal buttons [OK]
Common Mistakes:
- Confusing vertical stacking with horizontal grouping
- Ignoring size classes like btn-group-lg
- Assuming default size when btn-group-lg is present
4. Identify the error in this Bootstrap button group code:
<div class='btn-group' aria-label='Button group'> <button class='btn btn-primary'>A</button> <button class='btn btn-primary'>B</button> <button class='btn btn-primary'>C</button> </div>
medium
Solution
Step 1: Check accessibility roles
Bootstrap button groups requirerole='group'on the container for screen readers to understand the grouping.Step 2: Validate other attributes and tags
Button type defaults to 'button' which is fine.btn-primaryis a valid class. Usingdivis correct for button groups.Final Answer:
Missingrole='group'attribute on the container div -> Option CQuick Check:
Button groups need role='group' for accessibility [OK]
Hint: Always add role='group' on btn-group container for accessibility [OK]
Common Mistakes:
- Omitting role='group' on the button group container
- Confusing button type attribute necessity
- Thinking btn-primary is invalid
5. You want to create a vertical button group with three buttons labeled 'Yes', 'No', and 'Maybe' that is also large in size. Which is the correct Bootstrap code snippet?
hard
Solution
Step 1: Identify vertical grouping class
The classbtn-group-verticalmakes the buttons stack vertically.Step 2: Combine vertical grouping with large size
Addingbtn-group-lgalongsidebtn-group-verticalon the container makes the entire group large and vertical.Step 3: Check button classes
Buttons have appropriate color classes and do not need individualbtn-lgif the group is large.Final Answer:
Usebtn-group-vertical btn-group-lgon container with role='group' -> Option AQuick Check:
btn-group-vertical + btn-group-lg = large vertical group [OK]
Hint: Combine btn-group-vertical and btn-group-lg on container for large vertical group [OK]
Common Mistakes:
- Using btn-group-lg without btn-group-vertical for vertical layout
- Adding btn-lg to buttons instead of group container
- Mixing btn-group and btn-group-vertical classes incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
