A dismissible alert is a message box that users can close or hide by clicking a close button. It helps show important info that can be removed when no longer needed.
Click to reveal answer
beginner
Which Bootstrap class makes an alert dismissible?
The class alert-dismissible is added to the alert container to make it dismissible.
Click to reveal answer
beginner
What HTML element is used for the close button in a dismissible alert?
A <code><button></code> element with <code>btn-close</code> class and <code>data-bs-dismiss="alert"</code> attribute is used for the close button.
Click to reveal answer
intermediate
Why is it important to include aria-label="Close" on the dismiss button?
It improves accessibility by letting screen readers know the button's purpose is to close the alert.
Click to reveal answer
intermediate
How does Bootstrap handle the alert dismissal behavior?
Bootstrap uses JavaScript to listen for clicks on the close button and then removes the alert from the page smoothly.
Click to reveal answer
Which class do you add to a Bootstrap alert to make it dismissible?
Aalert-dismiss
Balert-close
Calert-hide
Dalert-dismissible
✗ Incorrect
The alert-dismissible class enables the alert to be closed by the user.
What attribute must the close button have to dismiss the alert?
Adata-dismiss="alert"
Bdata-bs-toggle="alert"
Cdata-bs-dismiss="alert"
Ddata-toggle="close"
✗ Incorrect
The data-bs-dismiss="alert" attribute tells Bootstrap to close the alert when the button is clicked.
Which element is typically used for the close button in a dismissible alert?
A<button>
B<span>
C<a>
D<div>
✗ Incorrect
A <button> element with the right classes and attributes is used for accessibility and functionality.
Why should you add aria-label="Close" to the close button?
ATo help screen readers understand the button's purpose
BTo style the button
CTo improve keyboard navigation
DTo make the button bigger
✗ Incorrect
The aria-label helps screen readers announce the button as a close control.
What happens when you click the close button on a dismissible alert?
AThe alert changes color
BThe alert disappears smoothly
CThe alert reloads the page
DNothing happens
✗ Incorrect
Bootstrap's JavaScript removes the alert from the page with a smooth transition.
Explain how to create a dismissible alert in Bootstrap and why it is useful.
Think about the classes and attributes needed and the user experience.
You got /4 concepts.
Describe the accessibility features important for dismissible alerts in Bootstrap.
Focus on how screen readers and keyboard users interact with the alert.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a dismissible alert in Bootstrap?
easy
A. To make alerts appear with animation only
B. To allow users to close alert messages and keep the page clean
C. To change the alert color automatically
D. To disable all alerts on the page
Solution
Step 1: Understand the role of dismissible alerts
Dismissible alerts let users close alert messages so the page looks tidy and less cluttered.
Step 2: Compare options with this purpose
Only To allow users to close alert messages and keep the page clean describes this purpose correctly; others describe unrelated features.
Final Answer:
To allow users to close alert messages and keep the page clean -> Option B
Quick Check:
Dismissible alerts = user can close alerts [OK]
Hint: Dismissible means user can close it [OK]
Common Mistakes:
Thinking dismissible changes alert color
Confusing dismissible with animation only
Believing dismissible disables alerts
2. Which of the following is the correct Bootstrap class to make an alert dismissible?
easy
A. alert alert-dismissible
B. alert dismissible-alert
C. alert dismiss-alert
D. alert closeable
Solution
Step 1: Recall Bootstrap's dismissible alert class
The official class to make an alert dismissible is alert-dismissible combined with alert.
Step 2: Check each option
Only alert alert-dismissible uses the correct class names exactly as Bootstrap requires.
Final Answer:
alert alert-dismissible -> Option A
Quick Check:
Dismissible alert class = alert-dismissible [OK]
Hint: Look for exact class name alert-dismissible [OK]
Common Mistakes:
Using incorrect class names like dismissible-alert
Missing the alert class
Using non-Bootstrap class names
3. What will happen when the close button inside this alert is clicked?
B. Nothing will happen because the button is missing JavaScript
C. The alert text will change to 'Closed!'
D. The alert will fade out and disappear from the page
Solution
Step 1: Understand the alert structure and classes
The alert uses alert-dismissible, fade, and show classes with a close button having data-bs-dismiss="alert".
Step 2: Know Bootstrap's behavior on close button click
Clicking the button triggers Bootstrap's JavaScript to fade out and remove the alert from the page.
Final Answer:
The alert will fade out and disappear from the page -> Option D
Quick Check:
Close button with data-bs-dismiss = alert hides alert [OK]
Hint: Close button with data-bs-dismiss hides alert [OK]
Common Mistakes:
Thinking alert text changes on close
Assuming no effect without extra JS code
Believing page reloads on close
4. Identify the error in this dismissible alert code:
<div class="alert alert-success alert-dismissible" role="alert">
Success! Your form was submitted.
<button type="button" class="btn-close" aria-label="Close"></button>
</div>
medium
A. The alert should not have alert-dismissible class
B. Alert is missing the fade class
C. Missing data-bs-dismiss="alert" on the close button
D. The button type should be submit
Solution
Step 1: Check the close button attributes
The close button must have data-bs-dismiss="alert" to trigger alert dismissal.
Step 2: Verify other classes and attributes
The alert-dismissible class is correct, fade is optional, and button type should be button, not submit.
Final Answer:
Missing data-bs-dismiss="alert" on the close button -> Option C
Quick Check:
Close button needs data-bs-dismiss attribute [OK]
Hint: Close button must have data-bs-dismiss="alert" [OK]
Common Mistakes:
Forgetting data-bs-dismiss attribute
Thinking fade class is mandatory
Using wrong button type
5. You want to create a dismissible alert that automatically disappears after 5 seconds but also allows manual close. Which approach is correct?
hard
A. Use a dismissible alert with btn-close and add JavaScript to remove it after 5 seconds
B. Add data-bs-auto-dismiss="5000" attribute to the alert div
C. Use only fade and show classes without close button
D. Set the alert class to alert-auto-close and no JavaScript needed
Solution
Step 1: Understand Bootstrap's dismissible alert features
Bootstrap does not provide automatic dismiss with a data attribute; manual close requires btn-close and data-bs-dismiss="alert".
Step 2: Implement auto-dismiss with JavaScript
To auto-remove after 5 seconds, add JavaScript code that removes the alert element after a timeout, while keeping manual close button.
Final Answer:
Use a dismissible alert with btn-close and add JavaScript to remove it after 5 seconds -> Option A
Quick Check:
Auto-dismiss needs JS plus dismissible alert [OK]
Hint: Auto-dismiss requires JS plus dismissible alert [OK]
Common Mistakes:
Assuming data-bs-auto-dismiss exists
Omitting the close button for manual close
Using non-existent alert-auto-close class
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.