Skip to content
All components
Feedback

Alert

Show a persistent, in-place message about the state of a page, section or task, with its severity and what to do next.

One status prop picks the fill, the border, the icon and the text.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add alert

Then import it from @/components/ui/alert. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Information

Present informational feedback with readable status content. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

export function AlertInformation() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <Alert status="information">
        <AlertTitle>Registry rebuilt</AlertTitle>
        <AlertDescription>57 items written to public/r.</AlertDescription>
      </Alert>
    </div>
  )
}

Success

Present successful-result feedback with readable status content. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Alert, AlertTitle } from "@/components/ui/alert"

export function AlertSuccess() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <Alert status="success" emphasis="light">
        <AlertTitle>Tokens in sync</AlertTitle>
      </Alert>
    </div>
  )
}

Warning

Present a warning with readable status content. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Alert, AlertTitle } from "@/components/ui/alert"

export function AlertWarning() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <Alert status="warning" emphasis="lighter">
        <AlertTitle>One item has no documentation page yet</AlertTitle>
      </Alert>
    </div>
  )
}

Error

Present error feedback with readable status content. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

export function AlertError() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <Alert status="error" emphasis="stroke">
        <AlertTitle>Build failed</AlertTitle>
        <AlertDescription>
          An item depends on a component that is not in the registry.
        </AlertDescription>
      </Alert>
    </div>
  )
}

With actions

Offer recovery actions inside an error alert. The actions are ordinary buttons placed after the description.

"use client"

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"

export function AlertWithActions() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <Alert status="error">
        <AlertTitle>Payment could not be processed</AlertTitle>
        <AlertDescription>
          The card was declined. Update the payment method to keep the workspace active.
        </AlertDescription>
        <div className="flex flex-wrap gap-2 pt-1">
          <Button size="xs" intent="neutral" emphasis="stroke">
            Update payment method
          </Button>
          <Button size="xs" intent="neutral" emphasis="ghost">
            Contact support
          </Button>
        </div>
      </Alert>
    </div>
  )
}

Polite status

Override the role to status for non-urgent information. Alert defaults to role alert, which interrupts screen reader users.

"use client"

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

export function AlertPoliteStatus() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <Alert status="information" role="status">
        <AlertTitle>Scheduled maintenance</AlertTitle>
        <AlertDescription>
          Sync pauses on Saturday from 02:00 to 03:00 UTC. Your data stays available.
        </AlertDescription>
      </Alert>
    </div>
  )
}

Without icon

Hide the status icon and keep the status in the text. The title says it is a warning, so meaning does not depend on the icon or color.

"use client"

import { Alert, AlertTitle } from "@/components/ui/alert"

export function AlertWithoutIcon() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <Alert status="warning" icon={false}>
        <AlertTitle>Warning: trial ends in 3 days</AlertTitle>
      </Alert>
    </div>
  )
}

Narrow width

Wrap a long unbroken address inside a narrow alert. The content wraps anywhere instead of overflowing the container.

"use client"

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

export function AlertNarrowWidth() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <div className="w-full max-w-72">
        <Alert status="warning" emphasis="stroke">
          <AlertTitle>Webhook endpoint unreachable</AlertTitle>
          <AlertDescription>
            https://hooks.example.com/workspaces/production/deliveries/retry-queue did not respond.
          </AlertDescription>
        </Alert>
      </div>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Alert

Present persistent contextual status or explanatory feedback.

Alert props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
emphasis"filled" | "stroke" | "lighter" | "light" | null | undefined"lighter"Visual treatment: filled, light, lighter or stroke. Preserve text contrast for the chosen status and surface.
status"error" | "success" | "warning" | "information" | null | undefined"information"Information, success, warning or error appearance. Include meaningful status text; color and icon do not replace it.
iconboolean | undefinedtrueWhether to render the built-in status icon. Keep the status understandable through text when hiding it.
Inherited props (13)
Alert inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

AlertDescription

Supporting text for this composition. Associate it with the relevant control when it conveys input help or errors.

AlertDescription props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
AlertDescription inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

AlertTitle

Visible title for this composition. Overlay titles also supply its accessible name when connected by the underlying primitive.

AlertTitle props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
AlertTitle inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/alert.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • An error that blocks progress in a section, such as a failed payment or a sync that stopped, with a recovery action.
  • A warning about something that will happen soon, such as a trial ending or a quota nearly reached.
  • A success or information message that must stay visible next to the content it refers to.
  • A form-level summary of errors at the top of a form, linking to the fields.

When not to use

  • A decision that must be confirmed before continuing; use an alert dialog.
  • A brief confirmation of a completed background action that does not need to stay; use a toast.
  • Validation of a single field; show the error under the field it belongs to.
  • Marketing or promotional content dressed up as a status message.

Anatomy

Alert
Container with role="alert" (overridable), a status (information, success, warning, error) and an emphasis (lighter by default, light, stroke, filled).
Status icon
Built-in icon chosen by status, hidden from assistive technology. icon={false} removes it.
AlertTitle
Short statement of what happened. Plain div; it does not name the alert automatically.
AlertDescription
Explanation and next step. Long unbroken text wraps instead of overflowing.
Actions
Optional buttons or links placed as children after the description; Alert has no built-in action slot.

Keyboard & interaction

  • The alert itself is not focusable; buttons and links inside it are normal Tab stops.
  • role="alert" is an assertive live region: content inserted into it is announced immediately. Use it for urgent changes that appear after page load.
  • Pass role="status" for non-urgent updates, which are announced politely without interrupting.
  • Alert has no dismiss or close behavior; if people can dismiss it, add a labeled close button and decide where focus goes after it is removed.

Responsive behavior

  • Alert fills the width of its container and its content wraps, including long URLs (overflow-wrap anywhere), so it reflows at 320 CSS pixels.
  • Put actions in a flex-wrap row so they stack under the text on narrow screens.
  • Keep alerts close to the content they describe; on small screens a page-level alert at the top can be far from the problem.

Content guidelines

  • Title: what happened, in a few words, with the severity implied by the words ('Build failed').
  • Description: why it matters and what to do next, in one or two sentences.
  • Action labels name the fix: 'Update payment method', 'Retry sync'.
  • Avoid blame and jargon; do not use exclamation marks or all caps for urgency.

Alternatives

  • Alert dialog — A consequential decision that interrupts the flow.
  • Sonner — A transient notification about a completed action.
  • Field — Inline validation messages tied to one control.
  • Empty — Explaining why a content area has nothing to show.

Resources