Alerts

Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.

Examples

Alerts are available for any length of text, as well as an optional close button. For proper styling, use one of the eight required contextual classes (e.g., theme="success").

vue
<template>
 <Alert color="primary">
  A simple primary alert—check it out!
 </Alert>
 <Alert color="secondary">
  A simple secondary alert—check it out!
 </Alert>
 <Alert color="success">
  A simple success alert—check it out!
 </Alert>
 <Alert color="danger">
  A simple danger alert—check it out!
 </Alert>
 <Alert color="warning">
  A simple warning alert—check it out!
 </Alert>
 <Alert color="info">
  A simple info alert—check it out!
 </Alert>
 <Alert color="light">
  A simple light alert—check it out!
 </Alert>
 <Alert color="dark">
  A simple dark alert—check it out!
 </Alert>
</template>

Link color

Use the AlertLink compoennt utility class to quickly provide matching colored links within any alert.

vue
<template>
 <Alert color="primary">
  A simple primary alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="secondary">
  A simple secondary alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="success">
  A simple success alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="danger">
  A simple danger alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="warning">
  A simple warning alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="info">
  A simple info alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="light">
  A simple light alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="dark">
  A simple dark alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
</template>

Additional content

Alerts can also contain additional HTML elements like headings, paragraphs and dividers.

vue
<template>
 <Alert color="success">
  <AlertHeading>Well done!</AlertHeading>
  <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 />
  <b-p margin="b-0">
   Whenever you need to, be sure to use margin utilities to keep things nice
   and tidy.
  </b-p>
 </Alert>
</template>

Icons

vue
<template>
 <Alert
  color="primary"
  flex
  align-items="center"
 >
  <BIcon
   icon="bi:exclamation-triangle-fill"
   flex="shrink-0"
   margin="e-2"
   aria-label="Warning:"
  />
  <div>An example alert with an icon</div>
 </Alert>
</template>

Need more than one icon for your alerts? Consider using more NuxtIcon and making a SVG sprite like so to easily reference the same icons repeatedly.

vue
<template>
 <Alert
  color="primary"
  flex
  align-items="center"
 >
  <BIcon
   v-bootstrap
   icon="bi:info-circle-fill"
   color="currentColor"
   flex="shrink-0"
   margin="e-2"
   aria-label="Info:"
  />
  <div>An example alert with an icon</div>
 </Alert>
 <Alert
  color="success"
  flex
  align-items="center"
 >
  <BIcon
   icon="bi:check-circle-fill"
   color="currentColor"
   flex="shrink-0"
   margin="e-2"
   aria-label="Success:"
  />
  <div>An example success alert with an icon</div>
 </Alert>
 <Alert
  color="warning"
  flex
  align-items="center"
 >
  <BIcon
   icon="bi:exclamation-triangle-fill"
   color="currentColor"
   flex="shrink-0"
   margin="e-2"
   aria-label="Warning:"
  />
  <div>An example warning alert with an icon</div>
 </Alert>
 <Alert
  color="danger"
  flex
  align-items="center"
 >
  <BIcon
   icon="bi:exclamation-triangle-fill"
   color="currentColor"
   flex="shrink-0"
   margin="e-2"
   aria-label="Danger:"
  />
  <div>An example danger alert with an icon</div>
 </Alert>
</template>

Dismissing

Using the CloseButton components, it's possible to dismiss any alert inline. Here's how:

You can see this in action with a live demo:

vue
<template>
 <Alert
  color="warning"
  dismissible
  fade
 >
  <strong>Holy guacamole!</strong>
  You should check in on some of those fields below.
  <CloseButton dismiss="alert" />
 </Alert>
</template>

Triggers

Dismissal can be achieved with the dismiss attribute on a button within the alert as demonstrated below:

vue
<template>
 <Alert
  color="warning"
  dismissible
  fade
 >
  <b-button
   color="primary"
   dismiss="alert"
  >
   Close
  </b-button>
  <strong>Holy guacamole!</strong>
  You should check in on some of those fields below.
  <CloseButton dismiss="alert" />
 </Alert>
</template>

or on a button outside the alert using the target as demonstrated below:

vue
<template>
 <Alert
  id="my-alert"
  color="warning"
  dismissible
  fade
 >
  <strong>Holy guacamole!</strong>
  You should check in on some of those fields below.
 </Alert>
 <b-button
  color="primary"
  dismiss="alert"
  target="#my-alert"
 >
  Close
 </b-button>
</template>

Methods

MethodDescription
toggle Manual switching
show Manually show
hide Manually hide