# Alert

> Alerts report the result of an action or a problem to fix, in success, info, warning and danger variants, with icons, links and a dismiss button.

Show alert messages that inform users about success, info, warning, or danger states, with icons, links, and dismissible options.

Source: https://docs.tabler.io/ui/components/alert

---

## Default markup

An alert comes in four types: success, info, warning and danger. Pick the one that matches the message, so the color says at a glance whether something went right or wrong.

Combine `alert` class with one of the following: `alert-success`, `alert-info`, `alert-warning`, `alert-danger` to get the alert that you need.

Alert classes affect the color of all the text inside an alert. Use another class, e.g. `text-secondary` to change the color of the alert's content.

```html
<div class="alert alert-success" role="alert">
  <div class="alert-icon">
    <!-- Download SVG icon from http://tabler.io/icons/icon/check -->
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
      <path d="M5 12l5 5l10 -10" />
    </svg>
  </div>
  <div>
    <h4 class="alert-heading">Wow! Everything worked!</h4>
    <div class="alert-description">Your account has been saved!</div>
  </div>
</div>
<div class="alert alert-info" role="alert">
  <div class="alert-icon">
    <!-- Download SVG icon from http://tabler.io/icons/icon/info-circle -->
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
      <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
      <path d="M12 9h.01" />
      <path d="M11 12h1v4h1" />
    </svg>
  </div>
  <div>
    <h4 class="alert-heading">Did you know?</h4>
    <div class="alert-description">Here is something that you might like to know.</div>
  </div>
</div>
<div class="alert alert-warning" role="alert">
  <div class="alert-icon">
    <!-- Download SVG icon from http://tabler.io/icons/icon/alert-triangle -->
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
      <path d="M12 9v4" />
      <path d="M10.363 3.591l-8.106 13.534a1.914 1.914 0 0 0 1.636 2.871h16.214a1.914 1.914 0 0 0 1.636 -2.87l-8.106 -13.536a1.914 1.914 0 0 0 -3.274 0" />
      <path d="M12 16h.01" />
    </svg>
  </div>
  <div>
    <h4 class="alert-heading">Uh oh, something went wrong</h4>
    <div class="alert-description">Sorry! There was a problem with your request.</div>
  </div>
</div>
<div class="alert alert-danger" role="alert">
  <div class="alert-icon">
    <!-- Download SVG icon from http://tabler.io/icons/icon/alert-circle -->
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
      <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
      <path d="M12 8v4" />
      <path d="M12 16h.01" />
    </svg>
  </div>
  <div>
    <h4 class="alert-heading">I'm so sorry&hellip;</h4>
    <div class="alert-description">Your account has been deleted and can't be restored.</div>
  </div>
</div>
```

## Alert links

Add a link to your alert message to redirect users to the details they need to complete or additional information they should read. Use `alert-link` class to style the link and match the text color.

```html
<div class="alert alert-danger" role="alert">
  <div class="alert-icon">
    <!-- Download SVG icon from http://tabler.io/icons/icon/alert-circle -->
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
      <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
      <path d="M12 8v4" />
      <path d="M12 16h.01" />
    </svg>
  </div>This is a danger alert<a href="#" class="alert-link">check it out</a>
</div>
```

Use `alert-action` instead when the link is the thing to do next rather than a word inside a sentence. It is underlined on its own line and drops the underline on hover.

```html
<div class="alert alert-danger" role="alert">
  <h4 class="alert-heading">An error occurred</h4>
  <div class="text-secondary">We could not save your changes.</div>
  <a href="#" class="alert-action">Try again</a>
</div>
```

## Alert with a list

Wrap several messages in a `ul` with the `alert-list` class. It removes the default list margin so the items sit flush inside the alert.

```html
<div class="alert alert-warning" role="alert">
  <h4 class="alert-heading">Check these fields</h4>
  <ul class="alert-list">
    <li>The email address is missing.</li>
    <li>The password is too short.</li>
  </ul>
</div>
```

## Minor alerts

Add `alert-minor` for a quieter alert. It drops the tinted background and keeps a plain border, so the color only shows in the icon and the heading. Use it where an alert would otherwise dominate the page.

```html
<div class="alert alert-minor alert-info alert-dismissible" role="alert">
  <div class="alert-heading">Did you know?</div>
  <div class="text-secondary">Here is something that you might like to know.</div>
  <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
<div class="alert alert-minor alert-success" role="alert">
  <div class="alert-heading">Everything worked</div>
  <div class="text-secondary">Your account has been saved.</div>
</div>
```

## Dismissible alerts

Add a close button to let the user dismiss the alert. It stays on the page until they do.

```html
<a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
```

```html
<div class="alert alert-danger alert-dismissible" role="alert">
  <div class="alert-icon">
    <!-- Download SVG icon from http://tabler.io/icons/icon/alert-circle -->
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
      <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
      <path d="M12 8v4" />
      <path d="M12 16h.01" />
    </svg>
  </div>This is a danger alert<a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
```

## Alerts with icons

An icon in front of the text repeats the type of the alert, which helps when several alerts are on the page.

Use the `alert-icon` class on an `<svg>` (or on an `<i>` when using the webfont) to provide the proper styling.

```html
<div class="alert alert-success" role="alert">
  <div class="d-flex">
    <div>
      <!-- Download SVG icon from http://tabler.io/icons/icon/check -->
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
        <path d="M5 12l5 5l10 -10" />
      </svg>
    </div>
    <div>
      <h4 class="alert-heading">Wow! Everything worked!</h4>
      <div class="text-secondary">Your account has been saved!</div>
    </div>
  </div>
</div>
<div class="alert alert-info" role="alert">
  <div class="d-flex">
    <div>
      <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
        <path stroke="none" d="M0 0h24v24H0z" fill="none" />
        <circle cx="12" cy="12" r="9" />
        <line x1="12" y1="8" x2="12.01" y2="8" />
        <polyline points="11 12 12 12 12 16 13 16" />
      </svg>
    </div>
    <div>
      <h4 class="alert-heading">Did you know?</h4>
      <div class="text-secondary">Here is something that you might like to know.</div>
    </div>
  </div>
</div>
<div class="alert alert-warning" role="alert">
  <div class="d-flex">
    <div>
      <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
        <path stroke="none" d="M0 0h24v24H0z" fill="none" />
        <path d="M12 9v2m0 4v.01" />
        <path d="M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75" />
      </svg>
    </div>
    <div>
      <h4 class="alert-heading">Uh oh, something went wrong</h4>
      <div class="text-secondary">Sorry! There was a problem with your request.</div>
    </div>
  </div>
</div>
<div class="alert alert-danger" role="alert">
  <div class="d-flex">
    <div>
      <!-- Download SVG icon from http://tabler.io/icons/icon/alert-circle -->
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
        <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
        <path d="M12 8v4" />
        <path d="M12 16h.01" />
      </svg>
    </div>
    <div>
      <h4 class="alert-heading">I'm so sorry…</h4>
      <div class="text-secondary">Your account has been deleted and can't be restored.</div>
    </div>
  </div>
</div>
```

## Alert with avatar

Put an [avatar](/ui/components/avatar) in the alert when the message is about a person, such as a mention or a request.

```html
<div class="alert alert-success" role="alert">
  <div class="d-flex">
    <div>
      <span class="avatar me-3" style="background-image: url(/static/avatars/039m.jpg)"></span>
    </div>
    <div> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. </div>
  </div>
</div>
<div class="alert alert-info" role="alert">
  <div class="d-flex">
    <div>
      <span class="avatar me-3">JL</span>
    </div>
    <div> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. </div>
  </div>
</div>
<div class="alert alert-warning" role="alert">
  <div class="d-flex">
    <div>
      <span class="avatar me-3" style="background-image: url(/static/avatars/035f.jpg)"></span>
    </div>
    <div> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. </div>
  </div>
</div>
<div class="alert alert-danger" role="alert">
  <div class="d-flex">
    <div>
      <span class="avatar me-3" style="background-image: url(/static/avatars/056f.jpg)"></span>
    </div>
    <div> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. </div>
  </div>
</div>
```

## Alert with buttons

Add [buttons](/ui/components/button) when the alert asks the user to do something, for example to confirm or to retry.

Buttons don't inherit the alert's color, so you should set the proper class if you want it to be matched. For example, `btn-success` for `alert-success`.

```html
<div class="alert alert-success alert-dismissible" role="alert">
  <h3 class="mb-1">Some Title</h3>
  <p class="text-secondary">Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.</p>
  <div class="btn-list">
    <a href="#" class="btn btn-success">Okay</a>
    <a href="#" class="btn">Cancel</a>
  </div>
  <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
<div class="alert alert-info alert-dismissible" role="alert">
  <h3 class="mb-1">Some Title</h3>
  <p class="text-secondary">Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.</p>
  <div class="btn-list">
    <a href="#" class="btn btn-info">Okay</a>
    <a href="#" class="btn">Cancel</a>
  </div>
  <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
<div class="alert alert-warning alert-dismissible" role="alert">
  <h3 class="mb-1">Some Title</h3>
  <p class="text-secondary">Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.</p>
  <div class="btn-list">
    <a href="#" class="btn btn-warning">Okay</a>
    <a href="#" class="btn">Cancel</a>
  </div>
  <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
<div class="alert alert-danger alert-dismissible" role="alert">
  <h3 class="mb-1">Some Title</h3>
  <p class="text-secondary">Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.</p>
  <div class="btn-list">
    <a href="#" class="btn btn-danger">Okay</a>
    <a href="#" class="btn">Cancel</a>
  </div>
  <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
```

## Important alerts

Add `alert-important` to fill the whole alert with its color. Use it for messages that must not be missed.

```html
<div class="alert alert-important alert-success alert-dismissible" role="alert">...</div>
```

You can also use other elements, like icons and dismissible buttons, with this type of alert.

```html
<div class="alert alert-important alert-success alert-dismissible" role="alert">
  <div class="d-flex">
    <div>
      <!-- Download SVG icon from http://tabler.io/icons/icon/check -->
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
        <path d="M5 12l5 5l10 -10" />
      </svg>
    </div>
    <div>Wow! Everything worked!</div>
  </div>
  <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
<div class="alert alert-important alert-danger alert-dismissible" role="alert">
  <div class="d-flex">
    <div>
      <!-- Download SVG icon from http://tabler.io/icons/icon/alert-circle -->
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
        <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
        <path d="M12 8v4" />
        <path d="M12 16h.01" />
      </svg>
    </div>
    <div>Your account has been deleted and can't be restored.</div>
  </div>
  <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
```

Links work here too. Both `alert-link` and `alert-action` follow the alert color, so they turn white on the solid background.

```html
<div class="alert alert-important alert-danger" role="alert">
  <div class="alert-icon">
    <!-- Download SVG icon from http://tabler.io/icons/icon/alert-circle -->
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
      <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
      <path d="M12 8v4" />
      <path d="M12 16h.01" />
    </svg>
  </div>An error occurred!<a href="#" class="alert-action">Try again</a>
</div>
<div class="alert alert-important alert-info" role="alert">
  <div class="alert-icon">
    <!-- Download SVG icon from http://tabler.io/icons/icon/info-circle -->
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="icon alert-icon">
      <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
      <path d="M12 9h.01" />
      <path d="M11 12h1v4h1" />
    </svg>
  </div>Your plan renews next week.<a href="#" class="alert-link">See the details</a>
</div>
```

## Custom alert color

You're not limited to the 4 default alert colors. You can use any [base color](/ui/base/colors) you want.

```html
<div class="alert alert-lime" role="alert">
  <h4 class="alert-heading">Wow! Everything worked!</h4>
  <div class="text-secondary">Your account has been saved!</div>
</div>
<div class="alert alert-cyan" role="alert">
  <h4 class="alert-heading">Did you know?</h4>
  <div class="text-secondary">Here is something that you might like to know.</div>
</div>
<div class="alert alert-blue" role="alert">
  <h4 class="alert-heading">You have a new friend on Facebook</h4>
  <div class="text-secondary">Say hello to your new friend!</div>
</div>
<div class="alert alert-pink alert-dismissible alert-important" role="alert">
  <div class="d-flex">
    <div>
      <span class="avatar me-3" style="background-image: url(/static/avatars/035f.jpg)"></span>
    </div>
    <div>
      <h4 class="alert-heading">Sophia just added a new post on Instagram</h4>
      <div>Be the first to see it!</div>
    </div>
  </div>
  <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
```

## Accessibility

- Give an alert a role that matches how urgent it is. `role="alert"` interrupts the screen reader and suits an error; `role="status"` waits for a pause and suits a confirmation.
- The live region has to exist before the message arrives. Render the container on page load and put the text into it, rather than inserting the whole alert at the moment of the event.
- Label the dismiss button with `aria-label="Close"`. `btn-close` has no text of its own.
- The icon is decoration, so the alert must still read correctly with the icon ignored. Keep the meaning in the heading and the text.
- Colour alone does not say "error". A red alert and a green one must differ in their words too.
- After dismissing an alert, move focus somewhere sensible. Focus left on a removed element falls back to the top of the page.

## SCSS variables

Use these SCSS variables to customize alerts. The default values are:

```scss
$alert-padding-y: 0.75rem;
$alert-padding-x: 1rem;
$alert-margin-bottom: 1rem;
$alert-link-font-weight: var(--font-weight-semibold);
$alert-border-width: var(--border-width);
$alert-border-color: var(--border-color-translucent);
$alert-shadow: rgba($dark, 0.04) 0 2px 4px 0;
$alert-heading-margin-bottom: 0.25rem;
$alert-icon-size: 1.25rem;
$alert-padding-inline-end: 3rem;
$alert-gap: 1rem;
```

_Source: `core/scss/_variables.scss`_
