The alert box takes the focus away from the current window, and forces the user to read the message.
Default Alert examples below. Use color="" to control <base-alert> color. Supported colors are "primary", "success", "danger", "warning" and "accent". >
Use icon="" to add an icon to <base-alert>. Choose any icon from our Icon Pack page.
Add a <base-alert-actions> tag at the bottom and add one or multiple buttons for preferred actions. You can use the baseAlertDismiss directive on any button inside the actions to allow users to close the alert.
Add close="true" to the <base-alert> to activate the default close (X) button. When the alert is closed, it emits a (closed) event.
Alerts support three visual variants: soft (default), solid, and outline.
Soft (Default)
Solid
Outline
Use the duration property to automatically close the alert after a specific amount of time (in milliseconds).
Run the following command to add this component to your project:
npx base-ui-cli add alert
For AI agents
Copy a prompt with the registry name, CLI install, and import — or add the Base UI MCP server.
npx -y base-ui-mcp
Base UI provides standalone components. Import the exact elements you want to use into your component.
// Install: npx base-ui-cli add alert
// Paths are relative to aliases.components (default: src/app/components)
import { AlertActionsComponent } from './alert/alert-actions/alert-actions.component';
import { AlertDismissDirective } from './alert/alert-dismiss.directive';
import { AlertComponent } from './alert/alert.component';
@Component({
selector: 'app-your-component',
imports: [
AlertActionsComponent,
AlertComponent,
AlertDismissDirective
],
template: `...`
})
export class YourComponent {} API for alert — generated from JSDoc in the library source.
| API | Member | Type | Default | Description |
|---|---|---|---|---|
base-alert | class | string | '' | Additional host CSS classes (merged via cn()). |
base-alert | color | AlertColor | '' | — |
base-alert | variant | AlertVariant | 'soft' | — |
base-alert | icon | string | undefined | undefined | — |
base-alert | close | boolean | false | — |
base-alert | duration | number | 0 | — |
base-alert | (closed) | void | — | Emits when closed occurs. |
base-alert-actions | — | — | — | Container for action buttons within an alert component. |
[baseAlertDismiss] | — | — | — | A directive that dismisses the parent `base-alert` when clicked. |
Content