Alert
Inline messages for status and feedback, with a neutral surface, a colored icon and a dismiss that collapses smoothly.
pnpm dlx shadcn@latest add https://hextaui.com/r/alert.jsonAdds the component, the HextaUI theme tokens and any HextaUI components it depends on.
Add the theme tokens to your global CSS, if you haven’t yet.
Install the dependencies.
pnpm add @base-ui/react @tabler/icons-react class-variance-authority cnCopy and paste the following code into your project.
components/ui/alert.tsx components/ui/button.tsx lib/motion.ts Update the import paths to match your project setup.
variant colors only the icon, so the surface stays neutral and status reads at a glance without shouting.
appearance="soft" drops the border and tints the whole surface with the variant color.
Title only, description only and no icon all line up without extra classes. The grid places each part in its own column.
Put buttons in <AlertAction />. They align with the first line of the title, even when it wraps.
Add <AlertClose /> to let people dismiss it. The alert collapses smoothly and the content below slides up. Dismiss it from the keyboard and focus moves to the next control, here “Reset”.
Pass open and onOpenChange to drive it from your own state. It animates both in and out.
Call event.preventDefault() in the close button’s onClick to keep the alert open, for example to ask for confirmation first.
Alerts that mount after the page has loaded fade and slide in, and screen readers announce them. Alerts already in the server HTML appear without motion.
Inline icons and links inside the description keep their own style. Use render to give the title a heading level.
The icon, content and close button mirror with the reading direction.
| Key | Action |
|---|---|
| Tab | Moves focus to links, actions and the close button inside the alert. |
| EnterSpace | Activates the focused close button. Once the alert has collapsed, focus moves to the next focusable element, or the previous one when nothing follows. |
destructiveandwarningalerts getrole="alert"and are announced right away. Every other variant getsrole="status"and waits for a pause.- The close button is labelled “Dismiss”. Pass
aria-labelto translate it. - Focus is never lost when a focused alert closes.
- With reduced motion on, alerts appear and disappear instantly.
Every part accepts the attributes of the element it renders. The variants are exported as alertVariants for styling other elements the same way.
| Prop | Type | Default |
|---|---|---|
variantColors the icon. destructive and warning are announced assertively. | "default" | "destructive" | "success" | "info" | "warning" | "default" |
appearance | "outline" | "soft" | "outline" |
open | boolean | – |
defaultOpen | boolean | true |
onOpenChangeCalled when the close button is pressed. | (open: boolean) => void | – |
render | ReactElement | (props, state) => ReactElement | <div> |
| Attribute | Description |
|---|---|
data-slot="alert" | Target the alert in CSS. |
data-variant | The current variant. |
data-appearance | The current appearance. |
data-ending-style | Present while the alert collapses after a dismiss. |
| Prop | Type | Default |
|---|---|---|
render | ReactElement | (props, state) => ReactElement | <div> |
| Attribute | Description |
|---|---|
data-slot="alert-title" | Target titles in CSS. |
| Prop | Type | Default |
|---|---|---|
render | ReactElement | (props, state) => ReactElement | <div> |
| Attribute | Description |
|---|---|
data-slot="alert-description" | Target descriptions in CSS. Plain links inside are underlined for you. |
| Prop | Type | Default |
|---|---|---|
render | ReactElement | (props, state) => ReactElement | <div> |
| Attribute | Description |
|---|---|
data-slot="alert-action" | Target the action area in CSS. |
A ghost <Button /> that closes the nearest alert. It accepts every Button prop and must be used inside <Alert />.
| Prop | Type | Default |
|---|---|---|
aria-label | string | "Dismiss" |
children | ReactNode | <IconX /> |
onClickCall event.preventDefault() to keep the alert open. | (event: MouseEvent) => void | – |
| Attribute | Description |
|---|---|
data-slot="alert-close" | Target the close button in CSS. |
- ButtonButtons in every variant and size, with a built-in loading, success and error flow that skips the spinner for fast requests.
- MotionThe easing curves, durations and reduced-motion check every component animates with, plus hooks for size morphs and sliding highlights.
- EmptyA placeholder for screens with nothing to show yet, with an icon, a message and the next action.
- ProgressA bar or ring that shows how far a task has come, eases between updates and slides while the total is unknown.
- SkeletonPlaceholders that wait 150ms before showing, take the exact size of the content they wrap, and fade it in without moving anything.
- SpinnerA loading indicator with Apple-style ticks or a breathing ring that can wait before showing and stay long enough not to flicker.
Used in Pro blocks
Blocks that build on Alert.
- MarkdownMarkdown rendering for AI answers. Handles streaming without half-typed syntax, tables you can copy and inline citations.
- BillingThe plan and usage page of an AI product. Handles credits running out mid-cycle, plan changes with proration and card errors.
Every block comes with HextaUI Pro, and Prompt Input is free.