# Alert

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/alert
- **Markdown:** https://refast.fastapicloud.dev/docs/components/alert.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/feedback/alert.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

An inline status message that draws the user's attention without
interrupting their workflow (unlike a dialog or toast).

```python
from refast.components import Alert

Alert(title="Success!", message="Your changes have been saved.", variant="success")
```

> **Heads up!**
> This is an example alert message.

```python
Alert(
    title="Heads up!",
    message="This is an example alert message.",
    variant="default",
    dismissible=False,
)
```

## Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `title` | `str \| None` | `None` | Bold heading of the alert |
| `message` | `str \| None` | `None` | Body text |
| `variant` | `"default" \| "success" \| "warning" \| "destructive" \| "info"` | `"default"` | Color and icon |
| `dismissible` | `bool` | `False` | Show a close button |
| `on_dismiss` | `Callback \| None` | `None` | Called when the close button is clicked |
| `children` | `ChildrenType` | `None` | Custom content inside the alert |
| `class_name` | `str` | `""` | Extra Tailwind classes |

## Variants

```python
Alert(title="Note", message="Informational message.", variant="default")
Alert(title="Success", message="Operation completed.", variant="success")
Alert(title="Warning", message="Proceed with caution.", variant="warning")
Alert(title="Error", message="Something went wrong.", variant="destructive")
Alert(title="Info", message="Here is some information.", variant="info")
```

## Dismissible Alert

```python
async def handle_dismiss(ctx: Context):
    ctx.state.set("show_alert", False)
    await ctx.refresh()

# In your render function:
Alert(
    title="Session expiring",
    message="Your session will expire in 5 minutes.",
    variant="warning",
    dismissible=True,
    on_dismiss=ctx.callback(handle_dismiss),
)
```

## With Custom Children

```python
Alert(
    title="Custom content",
    children=[
        Text("This alert has a custom body with rich content."),
        Button("Take action", size="sm", variant="outline", class_name="mt-2"),
    ]
)
```

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
