October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Create and Dismiss Bootstrap Alerts

Build a Bootstrap alert with the right variant, accessible message, and optional JavaScript-powered close button.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create an alert with Bootstrap’s .alert class and a contextual variant such as .alert-success. To let visitors dismiss it, include Bootstrap’s JavaScript alert plugin and add a close button with data-bs-dismiss="alert". The examples below use the documented Bootstrap v5.3 API; “V12” is not identified in the official documentation as an alert or Bootstrap release.

Make a basic Bootstrap alert

Bootstrap alerts are for important process information, such as an error that needs attention. Add role="alert" and describe the message in text, rather than relying on its color to convey meaning.

As an Amazon Associate I earn from qualifying purchases.

<div class="alert alert-success" role="alert">
  Your changes have been saved.
</div>

The official Bootstrap v5.3 alerts documentation shows eight contextual variants:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • alert-primary
  • alert-secondary
  • alert-success
  • alert-danger
  • alert-warning
  • alert-info
  • alert-light
  • alert-dark

Choose the variant that fits your design, but make the actual message understandable without color. Bootstrap warns that some default color combinations may fall below recommended WCAG 2.2 contrast ratios; check the foreground and background colors you use rather than assuming every variant passes. See the Bootstrap accessibility guidance.

Make an alert dismissible

A dismissible alert needs Bootstrap’s alert JavaScript behavior, the alert-dismissible class, and a semantic button carrying data-bs-dismiss="alert". Bootstrap’s compiled JavaScript or alert plugin is required; the data attribute lets Bootstrap initialize the dismissal behavior.

<div class="alert alert-warning alert-dismissible fade show" role="alert">
  <strong>Check this:</strong> Review the information before continuing.
  <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>

The fade and show classes provide the documented dismissal animation. The button’s accessible name comes from aria-label="Close"; keep it a button rather than substituting a non-interactive icon.

Account for focus when an alert closes

Bootstrap removes a dismissed alert from the DOM. If someone was focused on its close button, that removal can leave keyboard focus without a useful destination. For alerts where this matters, listen for the closed.bs.alert event and deliberately move focus to the next appropriate control or to a suitable page location made focusable. Bootstrap describes the removal behavior in its alert events documentation.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose an alert or a toast

Use an alert when the information is important to completing a process, such as correcting a form error. A toast is for a lightweight notification. An automatically disappearing message may vanish before someone can read or act on it, so choose the component and timing according to the message’s importance.

For toasts, Bootstrap says the live region should exist before the toast is inserted, and its role and urgency should suit the message. Follow the Bootstrap toast accessibility guidance when implementing one.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Version and licensing notes

This guide follows the official Bootstrap v5.3 documentation, not a verified “Alert V12” release. The v5.3 alert page notes that alerts gained local CSS variables in v5.2.0 and that the alert-variant() Sass mixin is deprecated as of v5.3.0. Check the documentation for the Bootstrap version in your project if you use another release.

Bootstrap’s getting-started page states that the framework is MIT-licensed and its documentation is licensed under CC BY 3.0. It also directs users to package managers for source files and identifies alerts as a component requiring JavaScript for dismissal.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.