Alerts
Vue Bootstrap 5 Alerts component
Responsive Alerts built with the latest Bootstrap 5 and Vue 3. Alerts provide contextual feedback messages for typical user actions with a handful of responsible and flexible alert boxes.
Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
Note: Read the API tab to find all available options and advanced customization
Basic examples
Click the buttons to launch the alerts.
Static examples
Link Color
Icons
Use Font Awesome Icons to create alerts with icons. Depending on your icons and content, you may want to add more utilities or custom styles.
Additional Content
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.
Dismissing
Using the Vue alert component, it’s possible to dismiss any alert inline. Here’s how:
-
Add a
dismiss
property, which adds close button and extra padding to the right of the alert which positions the close button. - Click on the close button to dismiss the alert.
You can see this in action with a live demo:
Show
You can manually show alert using show()
method on the alert component ref.
Hide
You can manually hide alert using hide()
method on alert component ref.
Placement
You can set the position of every alert using the
position
property.
Select horizontal / vertical alignment
Current position: top-right
Container
You can display an alert anywhere. Just put it in your target element and fill the
data-mdb-container
attribute with id or class of parent.
Offset
You can set offset of your alert using a
offset
> property.
Stacking
You can turn on stacking your alerts using the
stacking
property.
Stacking - Container
You can also stack alerts inside the container
Alerts - API
Import
Properties
Name | Type | Default | Description |
---|---|---|---|
tag
|
String | 'div' |
Defines tag of the MDBAlert element |
position
|
String | 'top-right' |
Sets a position for the alert. Any combination of 'vertical-horizontal' position: 'top|bottom-left|center|right' |
delay
|
Number | 5000 |
Sets the length of animation delay |
autohide
|
Boolean | true |
Alerts will hide automatically or not |
width
|
String | 'unset' |
Sets width of alert |
stacking
|
Boolean | true |
Enables stacking alerts |
offset
|
String | '10 |
Changes alert offset |
container
|
String | '' |
Defines container selector |
appendToBody
|
Boolean | false |
Appends element to the end of the body |
color
|
String | null |
Allows to set the color of an alert - primary | secondary | secondary | danger | warning | info | light | dark |
dismiss
|
Boolean | false |
Makes alert dismissible with close button |
animation
|
Boolean | true |
Allows to turn on or off the showing and hiding alert animation |
heightAnimation
|
Boolean | false |
Animates alert height change |
static
|
Boolean | false |
Makes alert static (open by default) |
hidden
|
Boolean | false |
Makes static alert hidden |
id
|
String | 'MDBAlert-generated id' |
Allows to add custom id to alert element |
v-model |
String | '' |
Returns current picked time |
Methods
Name | Description | Example |
---|---|---|
show |
Manually shows an alert |
alertRef.value.show()
|
hide |
Manually hides an alert |
alertRef.value.hide()
|
Events
Name | Description |
---|---|
show
|
This event fires immediately when the show method is called or `v-model` is set to true |
shown
|
This event fires immediately when the Alert is shown |
hide
|
This event fires immediately when the hide method is called or `v-model` is set to false |
hidden
|
This event fires immediately when the Alert is hidden |
CSS variables
As part of MDB’s evolving CSS variables approach, alerts now uses local CSS variables on
.alert
for enhanced real-time customization. Values for the CSS variables are set
via Sass, so Sass customization is still supported, too.