Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Feedback

Alert

Free15.0 KB gzipped

An inline, in-page message: info, success, warning, danger, or neutral. Not a toast or a banner; it sits in the flow of the content it relates to.

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab · Full report

Import

tsx
import { Alert } from "@vjdesigns/vjdesigns-ui";

Importing only Alert adds about 15.0 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.

Examples

Tones

Each tone has its own icon and a visually hidden label ("Warning:"), so meaning never depends on color.

Scheduled maintenance

The dashboard will be read-only on Sunday from 2–3 AM UTC.

Payment received

Thanks! Your receipt is on its way.

Warning: Storage almost full

You've used 92% of your storage.

Error: Couldn't save changes

Check your connection and try again.
tsx
import { Alert, Stack } from "@vjdesigns/vjdesigns-ui";

export function Tones() {
  return (
    <Stack gap={3} style={{ width: "100%" }}>
      <Alert tone="info" title="Scheduled maintenance">
        The dashboard will be read-only on Sunday from 2–3 AM UTC.
      </Alert>
      <Alert tone="success" title="Payment received">
        Thanks! Your receipt is on its way.
      </Alert>
      <Alert tone="warning" title="Storage almost full">
        You've used 92% of your storage.
      </Alert>
      <Alert tone="danger" title="Couldn't save changes">
        Check your connection and try again.
      </Alert>
    </Stack>
  );
}

Variants

Soft (default)

Solid

Outline

tsx
import { Alert, Stack } from "@vjdesigns/vjdesigns-ui";

export function Variants() {
  return (
    <Stack gap={3} style={{ width: "100%" }}>
      <Alert variant="soft" tone="info" title="Soft (default)" />
      <Alert variant="solid" tone="info" title="Solid" />
      <Alert variant="outline" tone="info" title="Outline" />
    </Stack>
  );
}

Dismissible with actions

dismissible adds a close button; focus moves somewhere sensible when it closes. actions adds buttons.

Warning: Your trial ends in 3 days

Upgrade to keep your projects and team members.
tsx
import { useState } from "react";
import { Alert, Button } from "@vjdesigns/vjdesigns-ui";

export function DismissibleWithActions() {
  const [open, setOpen] = useState(true);
  if (!open) {
    return (
      <Button variant="outline" tone="neutral" onClick={() => setOpen(true)}>
        Show alert again
      </Button>
    );
  }
  return (
    <div style={{ width: "100%" }}>
      <Alert
        tone="warning"
        title="Your trial ends in 3 days"
        dismissible
        onOpenChange={setOpen}
        actions={
          <Button size="sm" tone="neutral">
            Upgrade now
          </Button>
        }
      >
        Upgrade to keep your projects and team members.
      </Alert>
    </div>
  );
}

Accessibility

An alert's tone is also spoken (toneLabel, "Warning:"), so it doesn't depend on color or the icon. Use live only for alerts that appear in response to something, so they're announced; when a dismissed alert disappears, focus moves to returnFocusRef rather than getting lost.

tsx
import { useState } from "react";
import { Alert, Button, Stack } from "@vjdesigns/vjdesigns-ui";

export function Accessibility() {
  const [shown, setShown] = useState(false);
  return (
    <Stack gap={3} style={{ width: "100%", maxWidth: "32rem" }}>
      <Button variant="outline" tone="neutral" onClick={() => setShown(true)}>
        Check storage
      </Button>
      {shown && (
        <Alert tone="warning" title="Storage almost full" live="polite" dismissible onDismiss={() => setShown(false)}>
          You've used 92% of your 10 GB. Delete old files or upgrade your plan.
        </Alert>
      )}
    </Stack>
  );
}

Translated

The spoken tone ("Avertissement :") and the dismiss button's name come from the locale (French here).

Avertissement : Paiement en attente

Votre carte expire ce mois-ci. Mettez-la à jour pour éviter une interruption.
tsx
import { Alert, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import fr from "@vjdesigns/vjdesigns-ui/locales/fr";

export function Translated() {
  return (
    <LocaleProvider locale="fr" messages={fr}>
      <Alert tone="warning" title="Paiement en attente" dismissible style={{ width: "100%", maxWidth: "32rem" }}>
        Votre carte expire ce mois-ci. Mettez-la à jour pour éviter une interruption.
      </Alert>
    </LocaleProvider>
  );
}

Right to left

The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.

Tones

Scheduled maintenance

The dashboard will be read-only on Sunday from 2–3 AM UTC.

Payment received

Thanks! Your receipt is on its way.

تحذير: Storage almost full

You've used 92% of your storage.

خطأ: Couldn't save changes

Check your connection and try again.
tsx
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";

// Tones is the "Tones" example above.
<LocaleProvider locale="ar" messages={ar}>
  <Tones />
</LocaleProvider>

Usage notes

Accessibility:

  • Tone is never color alone: each tone has a distinct icon shape, and danger/warning get a visually hidden "Error: "/"Warning: " prefix (see toneLabel).
  • live picks the role: none (default), status (polite), or alert (assertive). Live roles only announce content inserted after page load.
  • The dismiss button is a native <button> named "Dismiss" (at least 32x32). After dismissal, focus moves to returnFocusRef when given.
  • With as="section" or as="aside", the landmark is labelled by the title.

API reference

Alert

Alert props
PropTypeDefault
tone

Semantic color and default icon.

"neutral""success""warning""danger""info""info"
variant

Surface style.

"soft""solid""outline""soft"
title

Bold display-font title. Optional; a description alone is fine for short messages.

ReactNode—
headingLevel

Renders the title as a real heading (h1-h6) at this level. Leave unset for a plain bold paragraph, which suits most inline alerts.

123456—
children

Description: the message body. May include links and lists.

ReactNode—
icon

Icon in the tinted circle. Defaults to a distinct shape per tone (info, success check, warning triangle, error). Pass false to hide it. Always decorative (hidden from assistive technology): the tone is also conveyed by toneLabel and the text.

ReactNode | false—
toneLabel

Visually hidden prefix read before the title (or the description, when there is no title), e.g. "Error: ". true uses the default for the tone, a string sets your own (localize it here), false turns it off.

string | booleanon for `danger` ("Error: ") and `warning` ("Warning: "), off otherwise
actions

Action row under the description, usually Buttons (size sm) or Links.

ReactNode—
dismissible

Shows a "Dismiss" icon button at the end.

booleanfalse
dismissLabel

Accessible name of the dismiss button. Localize it here.

string"Dismiss"
onDismiss

Called when the dismiss button is pressed, after the alert hides.

() => void—
returnFocusRef

Element to focus after dismissal, so keyboard focus isn't lost when the alert (and its dismiss button) disappears. Pick the control that triggered the alert, or the next logical element. If unset and focus was inside the alert, handle focus yourself in onDismiss.

RefObject<HTMLElement | null>—
open

Whether the alert is shown (controlled). Set with onOpenChange to control dismissal.

boolean—
defaultOpen

Whether the alert is shown initially (uncontrolled).

booleantrue
onOpenChange

Called with false when the alert is dismissed.

(open: boolean) => void—
live

Live-region behavior. See AlertLive.

"off""polite""assertive""off"
as

Root element. section and aside become labelled landmarks when there is a title.

"div""section""aside""div"
size

Padding, type size, and icon size.

"sm""md""lg""md"
radius

Corner rounding.

"none""xs""sm""md""lg""xl""2xl""pill""lg"

Also accepts native <div> attributes, plus className, style and ref.

See what changed in each version in the Changelog.

Accessibility report

Alert targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.

axe-core audit (live)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Dark mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.

Built-in behavior

Keyboard

Keyboard
KeyAction
TabMoves to the alert's action and close buttons; the alert itself isn't a tab stop.

Roles and states

Roles and states
ElementRoleStates and properties
Alert (default)noneRead in page order; not announced
live="polite"status—
live="assertive"alert—
Close buttonbuttonaria-label ("Dismiss")

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck.2.1.1 (A), 2.1.2 (A)
FocusFocus moves in a logical order, is always visible, and isn't hidden behind sticky headers.2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA)
Screen readersNames, roles and states are announced correctly, and status changes are announced without moving focus.1.3.1 (A), 4.1.2 (A), 4.1.3 (AA)
ColorMeaning never depends on color alone; your own colors meet contrast in both modes.1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA)
Zoom and reflowAt 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed.1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA)
Pointer targetsClick and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap.2.5.8 (AA), 2.5.5 (AAA)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)