Alert
On this page
Importing
Add rh-alert to your page with this import statement:
<script type="module">
import '@rhds/elements/rh-alert/rh-alert.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
To learn more about installing RHDS elements on your site using an import map read our getting started docs.
Usage
<rh-alert>
<h3 slot="header">Default</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est
egestas, a sollicitudin mauris tincidunt.</p>
<rh-button slot="actions" variant="secondary" data-action="confirm">Confirm</rh-button>
<rh-button slot="actions" variant="link" data-action="dismiss">Cancel</rh-button>
</rh-alert>
<script type="module">
import '@rhds/elements/rh-alert/rh-alert.js';
import '@rhds/elements/rh-button/rh-button.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
RhAlert.toast()
Accessibility considerations
There are accessibility considerations to keep in mind when using toasts. See our toast pattern accessibility guidelines for more information.
Toast alerts are created with the static RhAlert.toast() method. Full API
options, accessibility considerations, layout, and a live demo are documented on
the Alert pattern page. Do not author
<rh-alert variant="toast"> directly in HTML; use the JavaScript API.
import { RhAlert } from '@rhds/elements/rh-alert/rh-alert.js';
await RhAlert.toast({ state: 'success', message: 'Saved!' });
rh-alert
An alert provides a banner for status changes or messages.
It uses ARIA role="alert" so screen readers must announce
its content. Authors should provide a heading and must avoid
nesting alerts. Users may Tab to interactive elements and
press Enter to activate them. Meets WCAG 2.4.3.
Theming
This element uses Red Hat design system theming and can be used in themable contexts.
Slots
3
| Slot Name | Summary | Description |
|---|---|---|
actions
|
Up to two |
|
header
|
Alert heading; must be a heading element
(e.g. |
|
[default]
|
Body content for the alert; accepts block
elements like |
Attributes
3
| Attribute | DOM Property | Description | Type | Default |
|---|---|---|---|---|
state
|
state |
Communicates the urgency of a message and is denoted by various styling configurations.
Note: 'note', 'default', and 'error' will also work, but are deprecated |
|
|
variant
|
variant |
The alternate Inline alert style includes a border instead of a line which can be used to express more urgency or better grab the attention of a user. A Toast alert is used to present a global message about an event, update, or confirmation, like the result of a user action that cannot be presented within a specific layout or component. Toast alerts often appear away from what triggered them, may time out, automatically, and can be hard to discover in linear reading order. Toast alerts pose significant accessibility concerns and are not recommended for use. |
|
|
dismissable
|
dismissable |
Alert variants have different rules regarding their ability to be dismissed by a user. Default, Info, and Success Inline alerts can be dismissed by a user selecting the close button. Warning and Danger Inline alerts can be dismissed by a user resolving the issues caused by the alert. All Toast alerts can be dismissed by a user selecting the close button or waiting for them to time out. |
|
|
Methods
0
None
Events
1
| Event Name | Description |
|---|---|
close
|
Fires when dismissed via
close button or action click. |
CSS Shadow Parts
0
None
CSS Custom Properties
0
None
Design Tokens
38
| Token | Description | Copy |
|---|---|---|
--rh-space-xl
|
Action button inline end margin 24px spacer |
|
--rh-color-interactive-primary-default
|
Action link color |
|
--rh-color-interactive-primary-hover
|
Action link hover/focus color |
|
--rh-color-teal-10
|
Default surface color Alert - Default background |
|
--rh-color-teal-50
|
Default border color Default icon color Alert - Default accent |
|
--rh-border-width-md
|
Alert border width 2px border width: Example: Alert |
|
--rh-color-surface-dark
|
Alert dark mode surface color Tertiary surface (dark theme) |
|
--rh-space-lg
|
Footer block start margin Alert padding 16px spacer |
|
--rh-font-weight-body-text-regular
|
Alert font weight Regular font weight |
|
--rh-font-family-body-text
|
Alert font family Header font family Body text font family |
|
--rh-font-weight-body-text-medium
|
Header font weight Medium font weight |
|
--rh-line-height-body-text
|
Alert line height Header line height Line height for body text |
|
--rh-font-size-body-text-sm
|
Action button font size Alert font size Header font size Description font size 14px font size |
|
--rh-color-status-neutral
|
Neutral state border color |
|
--rh-color-icon-status-neutral
|
Neutral state icon color |
|
--rh-color-surface-status-neutral
|
Neutral state surface color |
|
--rh-color-status-info
|
Info state border color |
|
--rh-color-icon-status-info
|
Info state icon color |
|
--rh-color-surface-status-info
|
Info state surface color |
|
--rh-color-status-success
|
Success state border color |
|
--rh-color-icon-status-success
|
Success state icon color |
|
--rh-color-surface-status-success
|
Success state surface color |
|
--rh-color-status-caution
|
Caution state border color |
|
--rh-color-icon-status-caution
|
Caution state icon color |
|
--rh-color-surface-status-caution
|
Caution state surface color |
|
--rh-color-status-warning
|
Warning state border color |
|
--rh-color-icon-status-warning
|
Warning state icon color |
|
--rh-color-surface-status-warning
|
Warning state surface color |
|
--rh-color-status-danger
|
Danger state border color |
|
--rh-color-icon-status-danger
|
Danger state icon color |
|
--rh-color-surface-status-danger
|
Danger state surface color |
|
--rh-color-surface-lightest
|
Toast surface color Primary surface (light theme) |
|
--rh-box-shadow-xl
|
Toast box shadow Extra large box shadow |
|
--rh-space-xs
|
Header block end margin Grid gap Heading block end padding Close button area inline end margin 4px spacer |
|
--rh-size-icon-02
|
Status icon inline size Status icon block size 24px icon box |
|
--rh-color-text-secondary
|
Close button color |
|
--rh-length-xl
|
Close button block size Close button inline size 24px length token |
|
--rh-color-text-primary
|
Header text color Close button hover color |
|
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.