Toasts

Push notifications to your visitors with a toast, a lightweight and easily customizable alert message.

Basic Examples

To encourage extensible and predictable toasts, we recommend a header and body. Toast headers usedisplay: flex, allowing easy alignment of content thanks to our margin and flexbox utilities.

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";

const Page = () => {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <Toast show={isOpen} onClose={() => setIsOpen(false)}>
      <Toast.Header>
        <Image
          src="/images/docs/blackSquare.svg"
          className="rounded me-2"
          alt=""
        />
        <strong className="me-auto">Bootstrap</strong>
        <small>11 mins ago</small>
      </Toast.Header>
      <Toast.Body>Hello, world! This is a toast message.</Toast.Body>
    </Toast>
  );
};

export default Page;

Translucent

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";

const Page = () => {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <Toast show={isOpen} onClose={() => setIsOpen(false)}>
      <Toast.Header>
        <Image
          src="/images/docs/blackSquare.svg"
          className="rounded me-2"
          alt=""
        />
        <strong className="me-auto">Bootstrap</strong>
        <small>11 mins ago</small>
      </Toast.Header>
      <Toast.Body>Hello, world! This is a toast message.</Toast.Body>
    </Toast>
  );
};

export default Page;

Stacking

When you have multiple toasts, we default to vertically stacking them in a readable manner.

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";

const Page = () => {
  const [toastOne, setToastOne] = useState(false);
  const [toastTwo, setToastTwo] = useState(false);

  return (
    <Fragment>
      <Toast show={toastOne} onClose={() => setToastOne(false)}>
        <Toast.Header>
          <Image
            src="/images/docs/blackSquare.svg"
            className="rounded me-2"
            alt=""
          />
          <strong className="me-auto">Bootstrap</strong>
          <small>just now</small>
        </Toast.Header>
        <Toast.Body>See? Just like this.</Toast.Body>
      </Toast>

      <Toast
        show={toastTwo}
        onClose={() => setToastTwo(false)}
        className="mt-2"
      >
        <Toast.Header>
          <Image
            src="/images/docs/blackSquare.svg"
            className="rounded me-2"
            alt=""
          />
          <strong className="me-auto">Bootstrap</strong>
          <small>2 seconds ago</small>
        </Toast.Header>
        <Toast.Body>See? Just like this.</Toast.Body>
      </Toast>
    </Fragment>
  );
};

export default Page;

Custom content

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";

const Page = () => {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <Toast show={isOpen}>
      <div className="d-flex">
        <Toast.Body>Hello, world! This is a toast message.</Toast.Body>
        <Button
          variant="close"
          onClick={() => setIsOpen(false)}
          className="me-2 m-auto"
        ></Button>
      </div>
    </Toast>
  );
};

export default Page;

Alternatively, you can also add additional controls and components to toasts.

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";
const Page = () => {
  const [isOpen2, setIsOpen2] = useState(false);

  return (
    <Toast show={isOpen2}>
      <Toast.Body>
        Hello, world! This is a toast message.
        <div className="mt-2 pt-2 border-top">
          <Button variant="primary" size="sm">
            Take action
          </Button>{" "}
          <Button
            variant="secondary"
            size="sm"
            onClick={() => setIsOpen2(false)}
          >
            Close
          </Button>
        </div>
      </Toast.Body>
    </Toast>
  );
};

export default Page;

Color schemes

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";

const Page = () => {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <Toast
      bg="primary"
      className="align-items-center text-white border-0"
      show={isOpen}
    >
      <div className="d-flex">
        <Toast.Body>Hello, world! This is a toast message.</Toast.Body>
        <Button
          variant="close"
          className="btn-close-white me-2 m-auto"
          onClick={() => setIsOpen(false)}
        ></Button>
      </div>
    </Toast>
  );
};

export default Page;

Placement

Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you’re only ever going to show one toast at a time, put the positioning styles right on the .toast .

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";

const Page = () => {
  return (
    <div style={{ minHeight: "200px" }} className="position-relative">
      <Toast className="position-absolute top-0 end-0 ">
        <Toast.Header>
          <Image
            src="/images/avatar/avatar-1.jpg"
            alt=""
            className="rounded me-2 avatar-xs"
          />
          <strong className="me-auto">Bootstrap</strong>
          <small>11 mins ago</small>
        </Toast.Header>
        <Toast.Body>Hello, world! This is a toast message.</Toast.Body>
      </Toast>
    </div>
  );
};

export default Page;

For systems that generate more notifications, consider using a wrapping element so they can easily stack.

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";

const Page = () => {
  return (
    <div className="position-relative" style={{ minHeight: "200px" }}>
      <div className="position-absolute top-0 end-0">
        <Toast show={isOpen2} onClose={() => setIsOpen2(false)}>
          <Toast.Header>
            {" "}
            <Image
              src="/images/docs/blackSquare.svg"
              alt=""
              className="rounded me-2"
            />
            <strong className="me-auto">Bootstrap</strong>
            <small className="text-muted">just now</small>
          </Toast.Header>
          <Toast.Body>See? Just like this.</Toast.Body>
        </Toast>
      </div>
    </div>
  );
};

export default Page;

You can also get fancy with flexbox utilities to align toasts horizontally and/or vertically.

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";

const Page = () => {
  const [isOpen3, setIsOpen3] = useState(false);

  return (
    <div
      className="d-flex justify-content-center align-items-center"
      style={{ minHeight: "200px" }}
    >
      <Toast show={isOpen3} onClose={() => setIsOpen3(false)}>
        <Toast.Header>
          <Image src="/images/docs/blackSquare.svg" className="rounded me-2" />
          <strong className="me-auto">Bootstrap</strong>
          <small>11 mins ago</small>
        </Toast.Header>
        <Toast.Body>Hello, world! This is a toast message.</Toast.Body>
      </Toast>
    </div>
  );
};

export default Page;

Accessibility

Toasts are intended to be small interruptions to your visitors or users, so to help those with screen readers and similar assistive technologies, you should wrap your toasts in an aria-live region. Changes to live regions (such as injecting/updating a toast component) are automatically announced by screen readers without needing to move the user’s focus or otherwise interrupt the user. Additionally, include aria-atomic="true" to ensure that the entire toast is always announced as a single (atomic) unit, rather than announcing what was changed (which could lead to problems if you only update part of the toast’s content, or if displaying the same toast content at a later point in time). If the information needed is important for the process, e.g. for a list of errors in a form.

// import node module libraries
import { useState } from "react";
import Toast from "react-bootstrap/Toast";

const Page = () => {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <Toast show={isOpen} onClose={() => setIsOpen(false)}>
      <Toast.Header>
        <Image
          src="/images/docs/blackSquare.svg"
          alt=""
          className="rounded me-2"
        />
        <strong className="me-auto">Bootstrap</strong>
        <small>11 mins ago</small>
      </Toast.Header>
      <Toast.Body>Hello, world! This is a toast message.</Toast.Body>
    </Toast>
  );
};

export default Page;