Bootstrap Alerts: Styling and Usage Guide
Table of Content:
Alerts are available for any length of text, as well as an optional dismiss button. For proper styling, use one of the eight required contextual classes (e.g., .alert-success).
Only Important Code
This is primary alert—isn't it amazing?!This is secondary alert—isn't it amazing?!This is success alert—isn't it amazing?!This is danger alert—isn't it amazing?!This is warning alert—isn't it amazing?!This is info alert—isn't it amazing?!This is light alert—isn't it amazing?!This is dark alert—isn't it amazing?!
Full Code For The Above Example
See Live Preview of the above codeBootstrap Example This is primary alert—isn't it amazing?!This is secondary alert—isn't it amazing?!This is success alert—isn't it amazing?!This is danger alert—isn't it amazing?!This is warning alert—isn't it amazing?!This is info alert—isn't it amazing?!This is light alert—isn't it amazing?!This is dark alert—isn't it amazing?!
Only Important Code
Alerts
Alerts are created with the .alert class, followed by a contextual color classes:
Success! This alert box could indicate a successful or positive action.Info! This alert box could indicate a neutral informative change or action.Warning! This alert box could indicate a warning that might need attention.Danger! This alert box could indicate a dangerous or potentially negative action. Primary! Indicates an important action. Secondary! Indicates a slightly less important action. Dark! Dark grey alert. Light! Light grey alert.
Full Code For The Above Example
See Live Preview of the above codeBootstrap Example Alerts
Alerts are created with the .alert class, followed by a contextual color classes:
Success! This alert box could indicate a successful or positive action.Info! This alert box could indicate a neutral informative change or action.Warning! This alert box could indicate a warning that might need attention.Danger! This alert box could indicate a dangerous or potentially negative action. Primary! Indicates an important action. Secondary! Indicates a slightly less important action. Dark! Dark grey alert. Light! Light grey alert.
Additional content
Alerts can also contain additional HTML elements like headings, paragraphs and dividers.
If you will run above code, you will get below output.
Only Important Code
Well done!
Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.
Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
Full Code For The Above Example
See Live Preview of the above codeBootstrap Example Well done!
Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.
Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
Only Important Code
Well done!
Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.
Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
Full Code For The Above Example
See Live Preview of the above codeBootstrap Example Well done!
Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.
Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
Closing Alerts
To close the alert message, add a .alert-dismissible class to the alert container. Then add class="close" and data-dismiss="alert" to a link or a button element (when you click on this the alert box will disappear).
Only Important Code
Alerts
The button with class="close" and data-dismiss="alert" is used to close the alert box.
The alert-dismissible class adds some extra padding to the close button.
Success! This alert box could indicate a successful or positive action.
Full Code For The Above Example
See Live Preview of the above codeBootstrap Example Alerts
The button with class="close" and data-dismiss="alert" is used to close the alert box.
The alert-dismissible class adds some extra padding to the close button.
Success! This alert box could indicate a successful or positive action.Info! This alert box could indicate a neutral informative change or action.Warning! This alert box could indicate a warning that might need attention.Danger! This alert box could indicate a dangerous or potentially negative action.Primary! Indicates an important action.Secondary! Indicates a slightly less important action.Dark! Dark grey alert.Light! Light grey alert.
Animated Alerts
The .fade
and .show
classes adds a fading effect when closing the alert message:
Only Important Code
Animated Alerts
The .fade and .show classes adds a fading effect when closing the alert message.
Success! This alert box could indicate a successful or positive action.
Full Code For The Above Example
See Live Preview of the above codeBootstrap Example Animated Alerts
The .fade and .show classes adds a fading effect when closing the alert message.
Success! This alert box could indicate a successful or positive action.Info! This alert box could indicate a neutral informative change or action.Warning! This alert box could indicate a warning that might need attention.Danger! This alert box could indicate a dangerous or potentially negative action.Primary! Indicates an important action.Secondary! Indicates a slightly less important action.Dark! Dark grey alert.Light! Light grey alert.