Bootstrap Vue Toast Component

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

Vue toasts are lightweight notifications designed to mimic the push notifications that have been popularized by mobile and desktop operating systems. They’re built with flexbox, so they’re easy to align and position.

Overview

Things to know when using the toast plugin:

  • Toasts are opt-in for performance reasons, so you must initialize them yourself.
  • Toasts will automatically hide if you do not specify autohide: false.

Examples

Basic

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

Toasts are as flexible as you need and have very little required markup. At a minimum, we require a single element to contain your "toasted" content and strongly encourage a dismiss button.

<CToast :autohide="false">
  <CToastHeader closeButton>
    <svg
      class="rounded me-2"
      width="20"
      height="20"
      xmlns="http://www.w3.org/2000/svg"
      preserveAspectRatio="xMidYMid slice"
      focusable="false"
      role="img"
    >
      <rect width="100%" height="100%" fill="#007aff"></rect>
    </svg>
    <span class="me-auto fw-bold">Bootstrap Vue</span>
    <small>7 min ago</small>
  </CToastHeader>
  <CToastBody>Hello, world! This is a toast message.</CToastBody>
</CToast>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<template>
  <CButton color="primary" @click="createToast">Send a toast</CButton>
  <CToaster placement="top-end">
    <CToast v-for="(toast, index) in toasts">
      <CToastHeader closeButton>
      <span class="me-auto fw-bold">{{toast.title}}</span>
      <small>7 min ago</small>
      </CToastHeader>
      <CToastBody>
        {{ toast.content }}
      </CToastBody>  
    </CToast>
  </CToaster>
</template>
<script>
  export default {
    data() {
      return {
        toasts: []
      }
    },
    methods: {
      createToast() {
        this.toasts.push({
          title: 'new toast',
          content: 'Lorem ipsum dolor cet emit'
        })
      }
    }
  }
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Translucent

Toasts are slightly translucent to blend in with what's below them.

<CToast :autohide="false">
  <CToastHeader closeButton>
    <svg
      class="rounded me-2"
      width="20"
      height="20"
      xmlns="http://www.w3.org/2000/svg"
      preserveAspectRatio="xMidYMid slice"
      focusable="false"
      role="img"
    >
      <rect width="100%" height="100%" fill="#007aff"></rect>
    </svg>
    <span class="me-auto fw-bold">Bootstrap Vue</span>
    <small>7 min ago</small>
  </CToastHeader>
  <CToastBody>Hello, world! This is a toast message.</CToastBody>
</CToast>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Stacking

You can stack toasts by wrapping them in a toast container, which will vertically add some spacing.

<CToaster>
  <CToast :autohide="false">
    <CToastHeader closeButton>
      <svg
        class="rounded me-2"
        width="20"
        height="20"
        xmlns="http://www.w3.org/2000/svg"
        preserveAspectRatio="xMidYMid slice"
        focusable="false"
        role="img"
      >
        <rect width="100%" height="100%" fill="#007aff"></rect>
      </svg>
      <span class="me-auto fw-bold">Bootstrap Vue</span>
      <small>7 min ago</small>
    </CToastHeader>
    <CToastBody>Hello, world! This is a toast message.</CToastBody>
  </CToast>
  <CToast :autohide="false">
    <CToastHeader closeButton>
      <svg
        class="rounded me-2"
        width="20"
        height="20"
        xmlns="http://www.w3.org/2000/svg"
        preserveAspectRatio="xMidYMid slice"
        focusable="false"
        role="img"
      >
        <rect width="100%" height="100%" fill="#007aff"></rect>
      </svg>
      <span class="me-auto fw-bold">Bootstrap Vue</span>
      <small>7 min ago</small>
    </CToastHeader>
    <CToastBody>Hello, world! This is a toast message.</CToastBody>
  </CToast>
</CToaster>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

Custom content

Customize your toasts by removing sub-components, tweaking them with utilitiesopen in new window, or by adding your own markup. Here we've created a simpler toast by removing the default <CToastHeader>, adding a custom hide icon from CoreUI Iconsopen in new window, and using some flexbox utilitiesopen in new window to adjust the layout.

<CToast :autohide="false" class="align-items-center">
  <div class="d-flex">
    <CToastBody>Hello, world! This is a toast message.</CToastBody>
    <CToastClose class="me-2 m-auto"/>
  </div>
</CToast>
1
2
3
4
5
6

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

<CToast :autohide="false" class="align-items-center">
  <CToastBody>
    Hello, world! This is a toast message.
    <div class="mt-2 pt-2 border-top">
    <CButton type="button" color="primary" size="sm">
    Take action
    </CButton>
    <CToastClose component="CButton" color="secondary" size="sm" class="ms-1">Close</CToastClose>
    </div>
  </CToastBody>
</CToast>
1
2
3
4
5
6
7
8
9
10
11

Color schemes

Building on the above example, you can create different toast color schemes with our coloropen in new window and backgroundopen in new window utilities. Here we've set color="primary" and added .text-white class to the <Ctoast>, and then set white property to our close button. For a crisp edge, we remove the default border with .border-0.

<CToast :autohide="false" color="primary" class="text-white align-items-center">
  <div class="d-flex">
    <CToastBody>Hello, world! This is a toast message.</CToastBody>
    <CToastClose class="me-2 m-auto" white />
  </div>
</CToast>
1
2
3
4
5
6

API

CToast

import { CToast } from '@coreui/bootstrap-vue'
// or
import CToast from '@coreui/bootstrap-vue/src/components/toast/CToast'
1
2
3

Props

Prop nameDescriptionTypeValuesDefault
autohideAuto hide the toast.boolean-true
color* Sets the color context of the component to one of Bootstrap Vue’s themed colors.string'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light', string
delayDelay hiding the toast (ms).number-5000
dismissibleOptionally add a close button to component and allow it to self dismiss.boolean-true
indexindex of the component.number--
titleTitle node for your component.string--
visibleToggle the visibility of component.boolean-true

Events

Event nameDescriptionProperties
closeCallback fired when the component requests to be closed.
showCallback fired when the component requests to be shown.

CToastClose

import { CToastClose } from '@coreui/bootstrap-vue'
// or
import CToastClose from '@coreui/bootstrap-vue/src/components/toast/CToastClose'
1
2
3

Props

Prop nameDescriptionTypeValuesDefault
componentComponent used for the root node. Either a string to use a HTML element or a component.string--

Events

Event nameDescriptionProperties
closeEvent called before the dissmiss animation has started.

CToastHeader

import { CToastHeader } from '@coreui/bootstrap-vue'
// or
import CToastHeader from '@coreui/bootstrap-vue/src/components/toast/CToastHeader'
1
2
3

Props

Prop nameDescriptionTypeValuesDefault
close-buttonAutomatically add a close button to the header.boolean-

Events

Event nameDescriptionProperties
closeEvent called after clicking the close button.

CToaster

import { CToaster } from '@coreui/bootstrap-vue'
// or
import CToaster from '@coreui/bootstrap-vue/src/components/toast/CToaster'
1
2
3

Props

Prop nameDescriptionTypeValuesDefault
placementDescribes the placement of component.string'top-start', 'top', 'top-end', 'middle-start', 'middle', 'middle-end', 'bottom-start', 'bottom', 'bottom-end'-