# Alert

> Alert is a live region for messages that follow a user action. It announces itself when it appears, assertively by default or politely on request.

Source: https://vaneui.com/docs/basic-components/alert

Import: `import { Alert, Button, Col, Text } from "@vaneui/ui"`

Alert shows messages such as a save confirmation, a failed payment or an upload error. It renders a full-width `<div>` laid out as a flex row, in the `info` appearance unless another is set. A note that is part of the page from the first render fits a [Card](/docs/layout-components/card), and an error about one input fits the `error` prop of [Field](/docs/form-components/field). A message the user must answer before continuing belongs in a [Modal](/docs/overlay-components/modal).

## Basic usage

Alert is a live region: assistive technology announces its content when it appears, without the user having to find it. Use it for messages that result from something the user just did.

```tsx demo
<Alert>Scheduled maintenance starts at 02:00 UTC.</Alert>
```

By default it renders `role="alert"`, which interrupts. For a message that can wait for a natural pause, use `polite`, which renders `role="status"`.

```tsx demo
<Alert polite success>Your changes were saved.</Alert>
```

Render an Alert only when the message appears. An Alert present on first paint is not announced, because a live region announces changes, not initial content.

## Appearances

```tsx demo
<Col>
  <Alert info>A new version is available.</Alert>
  <Alert success polite>Your changes were saved.</Alert>
  <Alert warning>Your trial ends in three days.</Alert>
  <Alert danger>Payment failed. Update your card to continue.</Alert>
</Col>
```

## Variants

```tsx demo
<Col>
  <Alert danger>Outline, the default.</Alert>
  <Alert danger filled>Filled, for the loudest messages.</Alert>
</Col>
```

## With a title and actions

Alert is a flex row, so compose whatever the message needs.

```tsx demo
<Alert warning>
  <Col noGap>
    <Text fontSemibold>Your trial ends in three days</Text>
    <Text sm>Add a payment method to keep your projects running.</Text>
  </Col>
  <Button sm warning filled>Add card</Button>
</Alert>
```

## With an icon

A leading icon spans one text line, so it centres on the first line of the message.

```tsx demo
<Alert info>
  <Info />
  A new version is available. Reload to update.
</Alert>
```

## Font family

Alert text renders in the sans font (`fontSans`, the default) with body line-height, even when the page uses another font. Pass `fontMono` for a machine-style message.

```tsx demo
<Alert danger fontMono>Error 503: upstream connect error</Alert>
```

## Shapes

Alert is `rounded` by default. `sharp` suits an alert pinned to the edge of a panel, where a radius would leave a gap against the edge.

```tsx demo
<Col>
  <Alert>Rounded, the default</Alert>
  <Alert sharp>Sharp</Alert>
  <Alert pill>Pill</Alert>
</Col>
```

## Sizes

```tsx demo
<Col>
  <Alert xs>Extra small</Alert>
  <Alert sm>Small</Alert>
  <Alert>Medium, the default</Alert>
  <Alert lg>Large</Alert>
  <Alert xl>Extra large</Alert>
</Col>
```

## Props

| Prop | Category | Default | Description |
| --- | --- | --- | --- |
| `primary` | Appearance |  | Primary color appearance (gray) |
| `accent` | Appearance |  | Accent color appearance (rose) |
| `secondary` | Appearance |  | Secondary color appearance (gray) |
| `tertiary` | Appearance |  | Tertiary color appearance |
| `success` | Appearance |  | Success color appearance (green) |
| `danger` | Appearance |  | Danger color appearance (red) |
| `warning` | Appearance |  | Warning color appearance (amber) |
| `info` | Appearance | yes | Info color appearance (cyan) |
| `inheritAppearance` | Appearance |  | Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables |
| `desktopStack` | Breakpoint |  | Stack into a column at desktop width and below (max-desktop: 80rem) |
| `tabletStack` | Breakpoint |  | Stack into a column at tablet width and below (max-tablet: 64rem) |
| `mobileStack` | Breakpoint |  | Stack into a column at mobile width and below (max-mobile: 48rem) |
| `flex1` | Flex |  | Take up remaining space (= `flex-1`, i.e. `flex: 1 1 0%`) |
| `flexAuto` | Flex |  | Grow but respect intrinsic size (= `flex-auto`, i.e. `flex: 1 1 auto`) |
| `flexNone` | Flex |  | Don't grow and don't shrink (= `flex-none`, i.e. `flex: none`) |
| `fontSans` | Font Family | yes | Sans-serif font family (default) — emits font-sans |
| `fontSerif` | Font Family |  | Serif font family — emits font-serif |
| `fontMono` | Font Family |  | Monospace font family — emits font-mono |
| `fontHeading` | Font Family |  | Heading font family (defaults to sans, customizable via --font-heading) — emits font-heading |
| `margin` | Margin |  | Enable margin on all sides |
| `marginX` | Margin |  | Enable only horizontal (inline) margin |
| `marginY` | Margin |  | Enable only vertical (block) margin |
| `marginT` | Margin |  | Enable only top margin |
| `marginB` | Margin |  | Enable only bottom margin |
| `noMargin` | Margin |  | Disable margin (reset to 0) |
| `padding` | Padding | yes | Enable internal padding |
| `paddingX` | Padding |  | Enable only horizontal padding |
| `paddingY` | Padding |  | Enable only vertical padding |
| `noPadding` | Padding |  | Disable internal padding |
| `pill` | Shape |  | Fully rounded corners (circular) |
| `sharp` | Shape |  | No rounded corners (square) |
| `rounded` | Shape | yes | Medium rounded corners (default) |
| `noShrink` | Shrink |  | Prevent the flex item from shrinking below its content size (= `shrink-0`) |
| `xs` | Size |  | Extra small size |
| `sm` | Size |  | Small size |
| `md` | Size | yes | Medium size (default) |
| `lg` | Size |  | Large size |
| `xl` | Size |  | Extra large size |
| `textLeft` | Text Align |  | Align text to left (physical side, does not flip under RTL) |
| `textCenter` | Text Align |  | Align text to center |
| `textRight` | Text Align |  | Align text to right (physical side, does not flip under RTL) |
| `textJustify` | Text Align |  | Justify text |
| `textStart` | Text Align |  | Align text to the reading-direction start (left in LTR, right in RTL) |
| `textEnd` | Text Align |  | Align text to the reading-direction end (right in LTR, left in RTL) |
| `filled` | Variant |  | Filled variant - solid background with contrasting text color |
| `outline` | Variant | yes | Outline variant - transparent background with border and colored text (default) |
| `ghost` | Variant |  | Ghost variant - transparent background, no border, appearance-colored text, tinted hover background |

Layout and utility props (Border, Display, Flex Direction, Gap, Height, Hide, Items, Justify, Overflow, Position, Responsive Sizing, Responsive Width, Ring, Shadow, Show, Transparent, Width, Wrap) are listed on [Common Props](https://vaneui.com/docs/reference/common-props.md).
