Alerts
React Bootstrap 5 Alerts component
Responsive alerts built with Bootstrap 5, React 18 and Material Design 2.0. Examples of alerts popup such as warning, error or confirmation messages 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.
Show with trigger
You can manually show alert by changing value of the open
prop.
Hide
You can also manually hide alert using the open
prop.
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
containerRef
property with reference to the parent.
Offset
You can set offset or any other styling using the style
property.
Stacking
You can create stacking notifications using
MDBStack
component.
Stacking - Container
You can also stack alerts inside the container
Alerts - API
Import
Properties
MDBAlert
Name | Type | Default | Description | Example |
---|---|---|---|---|
alertRef
|
Reference | '' |
Reference to the alert element |
<MDBAlert alertRef={alertReference} />
|
appendToBody
|
Boolean | false |
Appends element to the end of the body |
<MDBAlert appendToBody />
|
autohide
|
Boolean | false |
Alerts will hide automatically or not |
<MDBAlert autohide />
|
color
|
String | '' |
Allows to set the color of an alert - primary | secondary | secondary | danger | warning | info | light | dark |
<MDBAlert color='secondary' />
|
containerRef
|
React.MutableRefObject |
null |
Defines a reference to the parent element |
<MDBAlert containerRef={containerReference} />
|
delay
|
Number | 1000 |
Sets the length of animation delay (in ms) |
<MDBAlert delay={2000} />
|
position
|
'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | '' |
Sets an alert position |
<MDBAlert position='top-right' />
|
open
|
Boolean | undefined |
Defines alert's open state.
Usually used with onClose event handler.
|
<MDBAlert open />
|
defaultOpen
|
Boolean | false |
Defines alert's default open state. No onClose handler is needed to close the alert. |
<MDBAlert defaultOpen />
|
width
|
Number | String | '' |
Sets width of alert (in pixels) |
<MDBAlert width={300} />
|
initialAnimation
|
boolean | false |
Defines if component should animate on initial render |
<MDBAlert initialAnimation />
|
animationVariants
|
{
open?: Record<string, any>;
closed?: Record<string, any>;
};
|
{open: { opacity: 1 },
closed: { opacity: 0 }}
|
Defines animation variants |
<MDBAlert animationVariants={
{open: { opacity: 1 },
closed: { opacity: 0 }}
} />
|
Events
Name | Type | Description |
---|---|---|
onOpen
|
() => void | Fired when the Alert starts to open. |
onOpened
|
() => void | Fired after opening transition has completed. |
onClose
|
() => void | Fires immediately when the Alert demands to be closed. |
onClosed
|
() => void | Fired after closing transition has completed. |
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.