Alerts
Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
Example
Alerts are available for any length of text, as well as an optional close button.
import { Alert } from 'react-bootstrap';
<Alert variant="primary">A simple primary alert—check it out!</Alert>
<Alert variant="secondary">A simple secondary alert—check it out!</Alert>
<Alert variant="success">A simple success alert—check it out!</Alert>
<Alert variant="danger">A simple danger alert—check it out!</Alert>
<Alert variant="warning">A simple warning alert—check it out!</Alert>
<Alert variant="info">A simple info alert—check it out!</Alert>
<Alert variant="light">A simple light alert—check it out!</Alert>
<Alert variant="dark">A simple dark alert—check it out!</Alert>
Link color
Also you can use link inside alert
'use client';
import { Alert } from 'react-bootstrap';
<Alert variant="primary">A simple primary alert with <Alert.Link href="/">an example link</Alert.Link>. Give it a click if you like.</Alert>
<Alert variant="secondary">A simple secondary alert with <Alert.Link href="#">an example link</Alert.Link>. Give it a click if you like.</Alert>
<Alert variant="success">A simple success alert with <Alert.Link href="#">an example link</Alert.Link>. Give it a click if you like.</Alert>
<Alert variant="danger">A simple danger alert with <Alert.Link href="#">an example link</Alert.Link>. Give it a click if you like.</Alert>
<Alert variant="warning">A simple warning alert with <Alert.Link href="#">an example link</Alert.Link>. Give it a click if you like.</Alert>
<Alert variant="info">A simple info alert with <Alert.Link href="#">an example link</Alert.Link>. Give it a click if you like.</Alert>
<Alert variant="light">A simple light alert with <Alert.Link href="#">an example link</Alert.Link>. Give it a click if you like.</Alert>
<Alert variant="dark">A simple dark alert with <Alert.Link href="#">an example link</Alert.Link>. Give it a click if you like.</Alert>
Additional content
Alerts can contain whatever content you like. Headers, paragraphs, dividers, go crazy.
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.
import { Alert } from 'react-bootstrap';
<Alert variant="success">
<Alert.Heading>Well done!</Alert.Heading>
<p>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.
</p>
<hr />
<p className="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
</Alert>
Icons
Similarly, you can use flexbox utilities to create alerts with icons. Depending on your icons and content, you may want to add more utilities or custom styles.
import { Alert } from 'react-bootstrap';
<Alert variant="primary d-flex"><Icon icon="alert-fill" className="icon me-1 mt-1" /> Example alert with an icon</Alert>
<Alert variant="success d-flex"><Icon icon="alert-fill" className="icon me-1 mt-1" /> Example success alert with an icon</Alert>
<Alert variant="warning d-flex"><Icon icon="alert-fill" className="icon me-1 mt-1" /> Example warning alert with an icon</Alert>
<Alert variant="danger d-flex"><Icon icon="alert-fill" className="icon me-1 mt-1" /> Example danger alert with an icon</Alert>
Dismissing
Using the alert JavaScript plugin, it’s possible to dismiss any alert inline. Here’s how:
'use client';
import { useState } from 'react';
import Alert from 'react-bootstrap/Alert';
import Button from 'react-bootstrap/Button';
export default function Example() {
const [show, setShow] = useState(true);
return (
<Alert variant="danger" onClose={() => setShow(false)} dismissible>
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
</Alert>
);
}