Home AssistantHome AssistantContributors
On this page
Could not connect to the device.This update requires a restart.You can change this later in the settings.Backup created.

Overview

An alert draws attention to a message on the page itself. It does not block anything: people can read it and continue. Its type, shown by a color and an icon, tells how serious the message is.

When to use

Use an alert for:

  • An error that someone needs to know about, with what to do about it
  • A warning about something that needs attention, or could go wrong
  • Useful context, like a tip or a change to be aware of
  • Confirming that something worked

Don't use an alert for:

  • A decision someone must make before they can continue. Use a dialog.
  • A short label or status next to something else. Use a badge.
  • Extra help that only shows on hover. Use a tooltip.

Anatomy

  1. Container: the tinted background, in the color of the type
  2. Icon: the icon of the type, or your own icon
  3. Title: optional, in bold above the message
  4. Message: the text of the alert
  5. Action: optional, a dismiss button or your own action, like a button

Variants

Type

There are four types. Each has its own color and icon:

  • Error: something went wrong. Say what, and what to do about it.
  • Warning: something needs attention, or could go wrong.
  • Info: useful context, like a tip or a change to be aware of. This is the default.
  • Success: something worked as intended.

With a title

A title adds a bold line above the message. Use it together with a message, never on its own.

This update requires a restart.

Dismissable or with an action

A dismissable alert gets a close button. You can also put your own action in the alert, like a button to undo.

You can change this later in the settings.Backup created.Undo

Narrow

In the narrow version, the action moves below the message instead of next to it. This helps in small spaces, like a card.

Behavior

  • An alert has no hover, focus, or pressed state of its own. Only the action inside it, like the dismiss button, has those.
  • Selecting the dismiss button does not remove the alert. It sends an event, and the page that shows the alert decides what happens, usually hiding it.
  • Long text wraps, and long words break, so the message always fits.
  • When there is no title, the icon is centered next to the message. With a title, it lines up with the title.
  • The alert is laid out left to right, unless its title starts with Hebrew or Arabic text. Then it follows the direction of the page.

Specs

Property Value Token
Padding 8px --ha-alert-padding
Icon size 24px --ha-alert-icon-size
Space between icon and message 8px None
Corner radius 4px --ha-border-radius-sm
Background The type color at 12% opacity See below
Title weight 700 --ha-font-weight-bold
Dismiss button size 36px --ha-icon-button-size
Type Icon Icon and background color
Error Alert circle outline --error-color, #db4437
Warning Alert outline --warning-color, #ffa600
Info Information outline --info-color, #039be5
Success Checkbox marked circle outline --success-color, #43a047

The message text has no color of its own: it uses the text color of the page around it.

Guidelines

Could not connect to the device. Check that it is turned on and connected to your network.
Do Say what went wrong, and what to do about it.
An error occurred.
Don't Only say that something went wrong.
This update requires a restart.
Do Use a title together with a message.
Don't Use a title without a message.

Accessibility

Keyboard

The alert itself does not take focus. Its action does:

Key Action
Tab Moves focus to the dismiss button or your own action.
Enter or Space Selects the focused button.

Target size

The dismiss button is 36px by 36px.

Screen readers

  • When an alert appears on a page that is already open, most screen readers read it out right away. An alert that is already there when the page loads is not announced.
  • Color and icon don't reach someone who uses a screen reader, so the text must make the type clear on its own.
  • The dismiss button is announced as "Dismiss alert", in the language of the user.

In the code

  • The alert has the role alert.
  • The icon is an ha-svg-icon, which is hidden from screen readers with aria-hidden="true".
  • The dismiss button is an icon button with the translated label ui.common.dismiss_alert as its accessible name.
  • Dialog: when someone must respond before continuing
  • Badge: a short status next to something
  • Color: the colors behind the types
  • UI text: how to write the message

In code

The element is <ha-alert>, with the type set through alert-type:

HTML
<ha-alert alert-type="error">Could not connect to the device.</ha-alert>
<ha-alert alert-type="warning" title="Restart required">
  This update requires a restart.
</ha-alert>
<ha-alert alert-type="success" dismissable>Backup created.</ha-alert>

Attributes

  • alert-type: info (default), warning, error, or success.
  • title: a title, shown in bold above the message.
  • dismissable: shows a dismiss button.
  • narrow: puts the action below the message.

Slots

  • Default: the message.
  • icon: replaces the icon of the type.
  • action: your own action, like a button. It replaces the dismiss button.

Events

  • alert-dismissed-clicked: fired when the dismiss button is selected. Remove or hide the alert in response.

Styling

  • --ha-alert-padding: the padding. Defaults to 8px.
  • --ha-alert-icon-size: the size of the icon. Defaults to 24px.

Source: src/components/ha-alert.ts

Was this page helpful?

Last updated on .