Alert
Display warning messages that require attention.
When To Use
- When you need to show alert messages to users.
- When you need a persistent static container which is closable by user actions.
Examples
-
Basic ·
basic -
More types ·
style -
Filled ·
filled -
Closable ·
closable -
Description ·
description -
Icon ·
icon -
Banner ·
banner -
Loop Banner ·
loop-banner -
Smoothly Unmount ·
smooth-closed -
ErrorBoundary ·
error-boundary -
Custom action ·
action -
Custom title alignment ·
custom-title-alignment -
Custom semantic dom styling ·
style-class
API
Common props ref:Common props
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| action | The action of Alert | ReactNode | - | × | |
Called when close animation is finished, please use closable.afterClose instead | () => void | - | × | ||
| banner | Whether to show as banner | boolean | false | × | |
| variant | Variant of Alert style | outlined | filled | outlined | 6.4.0 | 6.4.0 |
| classNames | Customize class for each semantic structure inside the component. Supports object or function | Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string> | - | 6.0.0 | |
| closable | The config of closable | boolean | ClosableType & React.AriaAttributes | false | closable.closeIcon, closable.aria-*: 5.15.0 | |
| closeIcon | (Only supports global configuration) Custom close icon | ReactNode | - | × | 5.14.0 |
| description | Additional content of Alert | ReactNode | - | × | |
| errorIcon | (Only supports global configuration) Custom error icon in Alert icon | ReactNode | - | × | 6.2.0 |
| icon | Custom icon, effective when showIcon is true | ReactNode | - | × | |
| infoIcon | (Only supports global configuration) Custom info icon in Alert icon | ReactNode | - | × | 6.2.0 |
Content of Alert, please use title instead | ReactNode | - | × | ||
Callback when Alert is closed, please use closable.onClose instead | (e: MouseEvent) => void | - | × | ||
Custom close icon, please use closable.closeIcon instead | ReactNode | - | - | × | |
Close text to show, please use closable.closeIcon instead | ReactNode | - | - | × | |
| showIcon | Whether to show icon | boolean | false, in banner mode default is true | × | |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function | Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties> | - | 6.0.0 | |
| successIcon | (Only supports global configuration) Custom success icon in Alert icon | ReactNode | - | × | 6.2.0 |
| title | Content of Alert | ReactNode | - | × | |
| type | Type of Alert styles, options: success, info, warning, error | string | info, in banner mode default is warning | × | |
| warningIcon | (Only supports global configuration) Custom warning icon in Alert icon | ReactNode | - | × | 6.2.0 |
ClosableType
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| afterClose | Called when close animation is finished | function | - | - |
| closeIcon | Custom close icon | ReactNode | - | - |
| onClose | Callback when Alert is closed | (e: MouseEvent) => void | - | - |
Alert.ErrorBoundary
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| description | Custom error description to show | ReactNode | {{ error stack }} | |
Custom error message to show, please use title instead | ReactNode | {{ error }} | ||
| title | Custom error title to show | ReactNode | {{ error }} |
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element with border, background, padding, border-radius, and positioning styles for the alert container | 6.0.0 |
icon | Icon element with color, line-height, and margin styles, supporting different status icon types | 6.0.0 |
section | Content element with flex layout controlling content area typography and minimum width | 6.0.0 |
title | Title element with text color and font styling for the alert title | 6.0.0 |
description | Description element with font-size and line-height styles for additional content | 6.0.0 |
actions | Actions element with layout and spacing styles for action buttons | 6.0.0 |
close | Close button element with basic button styling | 6.1.0 |
Semantic description source: vendor/components/alert/demo/_semantic.tsx
Design Token
Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.
| Token | Type | Native description |
|---|---|---|
borderRadius | CSSProperties['borderRadius'] | Border radius of alert |
defaultPadding | CSSProperties['padding'] | Default padding |
withDescriptionPadding | CSSProperties['padding'] | Padding with description |
withDescriptionIconSize | number | string | Icon size with description |
Declaration source: vendor/components/alert/style/index.ts
import type { CSSProperties } from 'react';
import type { CSSObject } from '@ant-design/cssinjs';
import { unit } from '@ant-design/cssinjs';
import { genFocusStyle, resetComponent } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks } from '../../theme/internal';
export interface ComponentToken {
// Component token here
/**
* @desc 组件圆角
* @descEN Border radius of alert
* @since 6.6.0
*/
borderRadius: CSSProperties['borderRadius'];
/**
* @desc 默认内间距
* @descEN Default padding
*/
defaultPadding: CSSProperties['padding'];
/**
* @desc 带有描述的内间距
* @descEN Padding with description
*/
withDescriptionPadding: CSSProperties['padding'];
/**
* @desc 带有描述时的图标尺寸
* @descEN Icon size with description
*/
withDescriptionIconSize: number | string;
}
type AlertToken = FullToken<'Alert'> & {
// Custom token here
};
Shared native props
Tips: The following generic properties apply to most antd components; those not supported are described separately.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
Install and reproduce an example
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.
Native type references
The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.
vendor/components/alert/Alert.tsxvendor/components/alert/ErrorBoundary.tsxvendor/components/alert/index.tsxvendor/components/alert/style/index.ts
Source and license
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.