logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
YouMindTRACTIANLobeHubCodeRabbit
6.4.5
  • Components Overview
  • Changelog
    v6.4.5
  • General
    • Button
    • FloatButton
    • Icon
    • Typography
  • Layout
    • Divider
    • Flex
    • Grid
    • Layout
    • Masonry
      6.0.0
    • Space
    • Splitter
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
    • Tabs
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPicker
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
      DEPRECATED
    • Popover
    • QRCode
    • Segmented
    • Statistic
    • Table
    • Tag
    • Timeline
    • Tooltip
    • Tour
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • App
    • BorderBeam
      6.4.0
    • ConfigProvider
    • Util
When To Use
Examples
Hooks usage (recommended)
Duration after which the notification box is closed
Notification with icon
Custom close button
Customized Icon
Placement
Update Message Content
Stack
Show with progress
Static Method (deprecated)
Customize progress bar color
Custom semantic styles
API
ClosableType
Global configuration
Semantic DOM
Design Token
FAQ
Why I can not access context, redux, ConfigProvider locale/prefixCls/theme in notification?
How to set static methods prefixCls ?

Notification

Prompt notification message globally.
Importimport { notification } from 'antd';
GitHub
components/notificationIssueOpen issues
Docs
Edit this pageLLMs.md
ModalPopconfirm

Resources

Ant Design X
Ant Design Charts
Ant Design Pro
Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Web3
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
X
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
For Agents
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTech logoMore Products

yuque logoYuQue-Document Collaboration Platform
AntV logoAntV-Data Visualization
Egg logoEgg-Enterprise Node.js Framework
Kitchen logoKitchen-Sketch Toolkit
Galacean logoGalacean-Interactive Graphics Solution
WeaveFox logoWeaveFox-AI Development with WeaveFox 🦊
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

When To Use

To display a notification message at any of the four corners of the viewport. Typically it can be used in the following cases:

  • A notification with complex content.
  • A notification providing a feedback based on the user interaction. Or it may show some details about upcoming steps the user may have to follow.
  • A notification that is pushed by the application.

Examples

API

Common props ref:Common props

  • notification.success(config)
  • notification.error(config)
  • notification.info(config)
  • notification.warning(config)
  • notification.open(config)
  • notification.destroy(key?: String)

The properties of config are as follows:

PropertyDescriptionTypeDefaultVersionGlobal Config
actionsCustomized button groupReactNode-5.24.0×
btnCustomized close button group, please use actions insteadReactNode--×
classNameCustomized CSS classstring--5.7.0
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
closableWhether to show the close buttonboolean | ClosableTypetrue-×
closeIconCustom close iconReactNodetrue5.7.0: close button will be hidden when setting to null or false5.14.0
descriptionThe content of notification box (required)ReactNode--×
durationTime in seconds before Notification is closed. When set to 0 or false, it will never be closed automaticallynumber | false4.5-×
showProgressShow progress bar for auto-closing notificationboolean5.18.0×
pauseOnHoverkeep the timer running or not on hoverbooleantrue5.18.0×
iconCustomized iconReactNode--×
keyThe unique identifier of the Notificationstring--×
titleThe title of notification boxReactNode-6.0.0×
messageThe title of notification box (deprecated), please use title insteadReactNode--×
placementPosition of Notification, can be one of top | topLeft | topRight | bottom | bottomLeft | bottomRightstringtopRight-×
roleThe semantics of notification content recognized by screen readers. The default value is alert. When set as the default value, the screen reader will promptly interrupt any ongoing content reading and prioritize the notification content for immediate attention.alert | statusalert5.6.0×
styleCustomized inline styleCSSProperties--5.7.0
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.0
onClickSpecify a function that will be called when the notification is clickedfunction--×
onCloseTrigger when notification closedfunction--×
propsAn object that can contain data-*, aria-*, or role props, to be put on the notification div. This currently only allows data-testid instead of data-* in TypeScript. See https://github.com/microsoft/TypeScript/issues/28960.Object--×
  • notification.useNotification(config)

The properties of config are as follows:

PropertyDescriptionTypeDefaultVersionGlobal Config
bottomDistance from the bottom of the viewport, when placement is bottom bottomRight or bottomLeft (unit: pixels)number24×
closeIconCustom close iconReactNodetrue5.7.0: close button will be hidden when setting to null or false5.14.0
getContainerReturn the mount node for Notification() => HTMLNode() => document.body×
placementPosition of Notification, can be one of top | topLeft | topRight | bottom | bottomLeft | bottomRightstringtopRight×
showProgressShow progress bar for auto-closing notificationboolean5.18.0×
pauseOnHoverkeep the timer running or not on hoverbooleantrue5.18.0×
rtlWhether to enable RTL modebooleanfalse×
stackNotifications will be stacked when amount is over thresholdboolean | { threshold: number }{ threshold: 3 }5.10.0×
topDistance from the top of the viewport, when placement is top topRight or topLeft (unit: pixels)number24×
maxCountMax Notification show, drop oldest if exceed limitnumber-4.17.0×

notification also provides a global config() method that can be used for specifying the default options. Once this method is used, all the notification boxes will take into account these globally defined options when displaying.

ClosableType

PropertyDescriptionTypeDefaultVersion
closeIconCustom close iconReactNodeundefined-
onCloseTrigger when notification closeFunctionundefined-

Global configuration

notification.config(options)

When you use ConfigProvider for global configuration, the system will automatically start RTL mode by default.(4.3.0+)

When you want to use it alone, you can start the RTL mode through the following settings.

notification.config

js
notification.config({
placement: 'bottomRight',
bottom: 50,
duration: 3,
rtl: true,
});
PropertyDescriptionTypeDefaultVersion
bottomDistance from the bottom of the viewport, when placement is bottom bottomRight or bottomLeft (unit: pixels)number24
closeIconCustom close iconReactNodetrue5.7.0: close button will be hidden when setting to null or false
durationTime in seconds before Notification is closed. When set to 0 or null, it will never be closed automaticallynumber4.5
getContainerReturn the mount node for Notification, but still display at fullScreen() => HTMLNode() => document.body
placementPosition of Notification, can be one of top topLeft topRight bottom bottomLeft bottomRightstringtopRight
showProgressShow progress bar for auto-closing notificationboolean5.18.0
pauseOnHoverkeep the timer running or not on hoverbooleantrue5.18.0
rtlWhether to enable RTL modebooleanfalse
topDistance from the top of the viewport, when placement is top topRight or topLeft (unit: pixels)number24
maxCountMax Notification show, drop oldest if exceed limitnumber-4.17.0

Semantic DOM

Design Token

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
colorErrorBgBackground color of error notification containerstring
colorInfoBgBackground color of info notification containerstring
colorSuccessBgBackground color of success notification containerstring
colorWarningBgBackground color of warning notification containerstring
progressBgBackground color of Notification progress barstringlinear-gradient(90deg, #69b1ff, #1677ff)
widthWidth of Notificationstring | number384
zIndexPopupz-index of Notificationnumber2050
Global TokenHow to use?
Token NameDescriptionTypeDefault Value
colorBgElevatedContainer background color of the popup layer, in dark mode the color value of this token will be a little brighter than `colorBgContainer`. E.g: modal, pop-up, menu, etc.string#ffffff
colorBgTextActiveControl the background color of text in active state.stringrgba(0,0,0,0.15)
colorBgTextHoverControl the background color of text in hover state.stringrgba(0,0,0,0.06)
colorErrorUsed to represent the visual elements of the operation failure, such as the error Button, error Result component, etc.string#ff4d4f
colorIconWeak action. Such as `allowClear` or Alert close buttonstringrgba(0,0,0,0.45)
colorIconHoverWeak action hover color. Such as `allowClear` or Alert close buttonstringrgba(0,0,0,0.88)
colorInfoUsed to represent the operation information of the Token sequence, such as Alert, Tag, Progress, and other components use these map tokens.string#1677ff
colorPrimaryBorderThe stroke color under the main color gradient, used on the stroke of components such as Slider.string#91caff
colorSuccessUsed to represent the token sequence of operation success, such as Result, Progress and other components will use these map tokens.string#52c41a
colorTextDefault text color which comply with W3C standards, and this color is also the darkest neutral color.stringrgba(0,0,0,0.88)
colorTextHeadingControl the font color of heading.stringrgba(0,0,0,0.88)
colorWarningUsed to represent the warning map token, such as Notification, Alert, etc. Alert or Control component(like Input) will use these map tokens.string#faad14
borderRadiusLGLG size border radius, used in some large border radius components, such as Card, Modal and other components.number8
borderRadiusSMSM size border radius, used in small size components, such as Button, Input, Select and other input components in small sizenumber4
boxShadowControl the box shadow style of an element.string 0 6px 16px 0 rgba(0,0,0,0.08), 0 3px 6px -4px rgba(0,0,0,0.12), 0 9px 28px 8px rgba(0,0,0,0.05)
controlHeightLGLG component heightnumber40
fontFamilyThe font family of Ant Design prioritizes the default interface font of the system, and provides a set of alternative font libraries that are suitable for screen display to maintain the readability and readability of the font under different platforms and browsers, reflecting the friendly, stable and professional characteristics.string-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'
fontSizeThe most widely used font size in the design system, from which the text gradient will be derived.number14
fontSizeLGLarge font sizenumber16
lineHeightLine height of text.number1.5714285714285714
lineHeightLGLine height of large text.number1.5
lineWidthFocusControl the width of the line when the component is in focus state.number3
marginControl the margin of an element, with a medium size.number16
marginLGControl the margin of an element, with a large size.number24
marginSMControl the margin of an element, with a medium-small size.number12
marginXSControl the margin of an element, with a small size.number8
marginXXLControl the margin of an element, with the largest size.number48
motionDurationMidMotion speed, medium speed. Used for medium element animation interaction.string0.2s
motionDurationSlowMotion speed, slow speed. Used for large element animation interaction.string0.3s
motionEaseInOutPreset motion curve.string
Cubic Bezier Visualizer
cubic-bezier(0.645, 0.045, 0.355, 1)External Link Icon
paddingContentHorizontalLGControl the horizontal padding of content element, suitable for large screen devices.number24
paddingLGControl the large padding of the element.number24
paddingMDControl the medium padding of the element.number20

FAQ

Why I can not access context, redux, ConfigProvider locale/prefixCls/theme in notification?

When you call notification methods, antd dynamically creates a React instance using ReactDOM.render, which runs in a different execution context than your original code.

When you need context info (like ConfigProvider context), you can use notification.useNotification to get api instance and contextHolder node. And put it in your children:

tsx
const [api, contextHolder] = notification.useNotification();
return (
<Context1.Provider value="Ant">
{/* contextHolder is inside Context1 which means api will get value of Context1 */}
{contextHolder}
<Context2.Provider value="Design">
{/* contextHolder is outside Context2 which means api will **not** get value of Context2 */}
</Context2.Provider>
</Context1.Provider>
);

Note: You must insert contextHolder into your children with hooks. You can use origin method if you do not need context connection.

App wrapper component can be used to simplify the problem of useNotification and other methods that need to manually implant contextHolder.

How to set static methods prefixCls ?

You can config with ConfigProvider.config

Hooks usage (recommended)

Use notification.useNotification to get contextHolder with context accessible issue. Please note that, we recommend to use top level registration instead of notification static method, because static method cannot consume context, and ConfigProvider data will not work.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Notification with icon

A notification box with a icon at the left side.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Customized Icon

The icon can be customized to any react node.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Update Message Content

Update content with unique key.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Show with progress

Show progress bar for auto-closing notification.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
5.18.0
Customize progress bar color

Customize the progress bar color by configuring the component token.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Duration after which the notification box is closed

Duration can be used to specify how long the notification stays open. After the duration time elapses, the notification closes automatically. If not specified, default value is 4.5 seconds. If you set the value to 0, the notification box will never close automatically.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Custom close button

To customize the style or font of the close button.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Placement

A notification box can appear from the top bottom topLeft topRight bottomLeft or bottomRight of the viewport via placement.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Stack

Stack configuration, enabled by default. Notifications will be stacked when the amount is over threshold. Up to 3 notifications are shown in the collapsed stack.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
5.10.0
Static Method (deprecated)

Static methods cannot consume Context provided by ConfigProvider. When enable layer, they may also cause style errors. Please use hooks version or App provided instance first.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Custom semantic styles

You can customize the semantic dom style of Notification with classNames and styles.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
6.0.0
Enabled:
Threshold:
Hello World!
Hello World?
Welcome back!
This is another notification.
  • root
    6.0.0
    Notice root element, set background color, border radius, shadow, padding and animation styles
  • wrapper
    6.4.0
    Wrapper element for icon and content with content layout styles
  • icon
    6.0.0
    Icon element, set absolute positioning, font size, line height and status color styles
  • section
    6.4.0
    Content section element that contains title and description
  • title
    6.0.0
    Title element, set color, font size, line height and margin styles
  • description
    6.0.0
    Description element, set font size, color and margin styles
  • close
    6.4.0
    Close button element, set position, size and interaction styles
  • actions
    6.0.0
    Actions element, set float right, top margin and action button layout styles
  • progress
    6.4.0
    Progress element, set progress styles for auto-closing notifications
  • list
    6.4.0
    Notification list root element, set positioning, z-index, width, scroll area and placement styles
  • listContent
    6.4.0
    Notification list content element, set notice layout, gap and height transition styles