A Bootstrap badge is a small count or label that helps highlight new or unread items, status, or counts next to text or icons.
Click to reveal answer
beginner
How do you add a badge to a button in Bootstrap?
You add a <span> with class badge inside the button element. For example: <button class='btn btn-primary'>Inbox <span class='badge bg-secondary'>4</span></button>
Click to reveal answer
beginner
What class do you use to change the color of a Bootstrap badge?
Use background utility classes like bg-primary, bg-success, bg-danger, etc., on the badge element to change its color.
Click to reveal answer
beginner
How can you make a badge appear as a pill shape in Bootstrap?
Add the class rounded-pill to the badge element to make it have rounded edges like a pill.
Click to reveal answer
intermediate
What accessibility feature should you consider when using badges?
Ensure badges have sufficient color contrast and use semantic HTML so screen readers can understand the badge content. Also, use aria-label if the badge content is not clear alone.
Click to reveal answer
Which class is required to create a badge in Bootstrap?
Amarker
Blabel
Cbadge
Dtag
✗ Incorrect
The class badge is used to create badge components in Bootstrap.
How do you make a Bootstrap badge have a pill shape?
AAdd class rounded-pill
BAdd class pill-badge
CAdd class badge-pill
DAdd class pill
✗ Incorrect
The class rounded-pill makes badges pill-shaped in Bootstrap.
Which class changes the badge background color to green in Bootstrap?
Abg-danger
Bbg-success
Cbg-primary
Dbg-warning
✗ Incorrect
bg-success applies a green background color to badges.
Where should you place the badge element to show a count on a button?
AInside the button element
BOutside the button element
CBefore the button element
DIn a separate div
✗ Incorrect
The badge <span> should be inside the button element to appear attached.
What should you check to make badges accessible?
ABadge animation
BBadge size only
CBadge font only
DColor contrast and semantic HTML
✗ Incorrect
Good color contrast and semantic HTML help badges be accessible to all users.
Explain how to create a badge in Bootstrap and customize its color and shape.
Think about the classes you add to a <span> element inside buttons or text.
You got /3 concepts.
Describe why accessibility matters for badges and how to improve it.
Consider users who rely on screen readers or have vision difficulties.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of a Bootstrap badge component?
easy
A. To style form input fields
B. To create large banners for page headers
C. To add navigation menus
D. To highlight small pieces of information like counts or labels
Solution
Step 1: Understand the badge role
Badges are used to show small bits of info such as counts or labels next to text or buttons.
Step 2: Compare options
Options A, B, and C describe other Bootstrap components or uses, not badges.
Final Answer:
To highlight small pieces of information like counts or labels -> Option D
Quick Check:
Badge = small info highlight [OK]
Hint: Badges show small info like numbers or labels [OK]
Common Mistakes:
Confusing badges with navigation or headers
Thinking badges style large elements
Using badges for form inputs
2. Which of the following is the correct syntax to create a Bootstrap badge with a primary color?
easy
A. New
B.
New
C. New
D. New
Solution
Step 1: Check Bootstrap badge syntax
Bootstrap badges use a span with class badge plus a background color class like bg-primary.
Step 2: Validate each option
New uses correct tags and classes. Options A, B, and D use incorrect tags or class names.
Final Answer:
<span class="badge bg-primary">New</span> -> Option C
Quick Check:
Use span.badge.bg-primary [OK]
Hint: Use <span> with classes badge and bg-color [OK]
B. The class 'badge-primary' is outdated; should use 'bg-primary' instead
C. The number 99 is too large for a badge
D. Missing closing tag for span
Solution
Step 1: Check Bootstrap badge color class
In Bootstrap 5+, color classes for badges use bg-primary, not badge-primary.
Step 2: Validate other parts
The span tag is correct, number size is fine, and the closing tag is present.
Final Answer:
The class 'badge-primary' is outdated; should use 'bg-primary' instead -> Option B
Quick Check:
Use bg-primary, not badge-primary [OK]
Hint: Use bg-primary for badge color, not badge-primary [OK]
Common Mistakes:
Using old Bootstrap 4 class names
Thinking span is invalid tag
Assuming number size matters
5. You want to add a badge inside a navigation link that shows the number of unread notifications. Which is the best way to do this for accessibility and styling?