Introducing PrimeReact v11-alpha šŸŽ‰Discover Now

Toast

An unstyled, accessible toast notification system with compound composition.

Build fully custom toast notifications with complete control over layout, animation, and styling.

basic-demo

Pre-styled Versions

Choose a pre-styled library to use Toast with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound API: Toaster (Root, Portal, Region) and Toast (Root, Content, Icon, Message, Title, Description, Action, Close)
  • Severity-aware icon rendering via <Toast.Icon match="...">
  • Global toast function with severity shortcuts (success, info, warn, error, secondary, contrast) plus update, dismiss, promise
  • Swipe-to-dismiss with directional detection
  • Stacked layout with expand-on-hover
  • Auto-timeout with pause on hover, interaction, and document visibility

Usage#

import { Toast } from 'primereact/toast';
import { Toaster, toast } from 'primereact/toaster';
<Toaster.Root>
    <Toaster.Portal>
        <Toaster.Region>
            {({ toaster }) =>
                toaster?.toasts?.map((t) => (
                    <Toast.Root key={t.id} toast={t}>
                        <Toast.Content>
                            <Toast.Icon match="success"><Check /></Toast.Icon>
                            <Toast.Icon match="error"><Times /></Toast.Icon>
                            <Toast.Icon match="warn"><ExclamationTriangle /></Toast.Icon>
                            <Toast.Icon match="info"><InfoCircle /></Toast.Icon>
                            <Toast.Message>
                                <Toast.Title />
                                <Toast.Description />
                                <Toast.Action />
                            </Toast.Message>
                            <Toast.Close />
                        </Toast.Content>
                    </Toast.Root>
                ))
            }
        </Toaster.Region>
    </Toaster.Portal>
</Toaster.Root>

Behavior#

Icon matching#

<Toast.Icon match="severity"> renders only for toasts of that severity. A <Toast.Icon /> without a match prop is the catch-all — it renders when the toast has no severity (e.g. a loading toast in toast.promise). A custom icon passed to toast({ icon }) overrides the matched block's children.

<Toast.Icon /> {/* catch-all (no severity) */}
<Toast.Icon match="success"><Check /></Toast.Icon>
<Toast.Icon match="error"><Times /></Toast.Icon>

Polymorphic rendering#

Use as on any sub-component to swap the rendered HTML element or render a custom React component.

<Toast.Close as="div">...</Toast.Close>
<Toast.Action as={MyButton}>...</Toast.Action>

Defaults: Toaster.Root=div, Toaster.Region=div, Toast.Root=li, Toast.Content=div, Toast.Message=div, Toast.Icon=span, Toast.Title=div, Toast.Description=div, Toast.Action=button, Toast.Close=button.

Render function children#

Toaster.Region accepts a render function as children, exposing the toaster instance for iterating over toasts.

<Toaster.Region>
    {({ toaster }) =>
        toaster?.toasts?.map((t) => (
            <Toast.Root key={t.id} toast={t}>...</Toast.Root>
        ))
    }
</Toaster.Region>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

ToasterRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToasterRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToasterRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToasterRootInstance—
The instance to pass to the component.
ptSafeRecord<ToasterRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToasterRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
positionToasterPosition'top-right'
Position of the toaster container
modeToasterMode'stacked'
Layout mode of the toaster.
limitnumber3
Maximum number of toasts to be visible
gapnumber14
Gap between toasts in pixels
timeoutnumber6000
Timeout for toast auto-dismiss (alias for duration)
groupstring—
Group identifier for toast grouping
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-positionCurrent position value

ToasterRegion#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToasterRegionInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToasterRegionInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToasterRegionInstance—
The instance to pass to the component.
ptSafeRecord<ToasterRegionPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToasterRegionInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-positionCurrent position value
data-expandedPresent when region is expanded

CSS custom properties — set on the Toaster.Region style for toast layout spacing.

VariableDescription
--gapVertical gap between toasts in pixels
--front-toast-heightHeight of the frontmost toast in pixels

ToasterPortal#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToasterPortalInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToasterPortalInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToasterPortalInstance—
The instance to pass to the component.
ptSafeRecord<ToasterPortalPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToasterPortalInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

ToastRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToastRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToastRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToastRootInstance—
The instance to pass to the component.
ptSafeRecord<ToastRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToastRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
toastToastType—
Toast data containing all toast information
toasterToasterRootInstance—
Reference to the parent Toaster instance
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-idToast identifier
data-indexToast index in the stack
data-mountedPresent after initial render
data-removedPresent during exit animation
data-visiblePresent when within the visible limit
data-frontPresent on the frontmost toast
data-expandedPresent when toaster is expanded
data-swipingPresent during active swipe
data-swipedPresent after swipe delta exceeds zero
data-swipe-outPresent after swipe threshold exceeded
data-swipe-directionSwipe direction (left, right, up, down)
data-dismissiblePresent when toast is dismissible

CSS custom properties — set on the Toast.Root style for swipe gestures and stacked positioning.

VariableDescription
--initial-heightInitial height of the toast before animation
--toast-indexIndex of the toast in the stack
--toast-z-indexZ-index stacking order for the toast
--toast-offsetVertical offset position in pixels
--swipe-amount-xHorizontal swipe distance in pixels
--swipe-amount-yVertical swipe distance in pixels

Defines passthrough(pt) options of ToastRoot component.

labeltypedescription
rootToastRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
bodyToastRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the body's DOM element.
contentToastRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content's DOM element.
iconToastRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the icon's DOM element.
titleToastRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the title's DOM element.
descriptionToastRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the description's DOM element.
actionToastRootPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the action button's DOM element.
closeToastRootPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the close button's DOM element.

ToastContent#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToastContentInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToastContentInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToastContentInstance—
The instance to pass to the component.
ptSafeRecord<ToastContentPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToastContentInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ToastContent component.

labeltypedescription
rootToastContentPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ToastMessage#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToastMessageInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToastMessageInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToastMessageInstance—
The instance to pass to the component.
ptSafeRecord<ToastMessagePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToastMessageInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ToastMessage component.

labeltypedescription
rootToastMessagePassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ToastTitle#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToastTitleInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToastTitleInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToastTitleInstance—
The instance to pass to the component.
ptSafeRecord<ToastTitlePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToastTitleInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ToastTitle component.

labeltypedescription
rootToastTitlePassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ToastDescription#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToastDescriptionInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToastDescriptionInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToastDescriptionInstance—
The instance to pass to the component.
ptSafeRecord<ToastDescriptionPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToastDescriptionInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ToastDescription component.

labeltypedescription
rootToastDescriptionPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ToastIcon#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToastIconInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToastIconInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToastIconInstance—
The instance to pass to the component.
ptSafeRecord<ToastIconPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToastIconInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
match"always" | ToastSeverity'always'
Restricts rendering to toasts of the given severity. Use `'always'` to render for any severity.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

The match prop restricts rendering to a specific severity. Use 'always' (or omit match) for the catch-all.

Defines passthrough(pt) options of ToastIcon component.

labeltypedescription
rootToastIconPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ToastAction#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToastActionInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToastActionInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToastActionInstance—
The instance to pass to the component.
ptSafeRecord<ToastActionPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToastActionInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ToastAction component.

labeltypedescription
rootToastActionPassThroughType<ButtonHTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

ToastClose#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToastCloseInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToastCloseInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToastCloseInstance—
The instance to pass to the component.
ptSafeRecord<ToastClosePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToastCloseInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ToastClose component.

labeltypedescription
rootToastClosePassThroughType<ButtonHTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen reader#

Toast uses role="alert", which implicitly sets aria-live to assertive and aria-atomic to true — screen readers announce toast content immediately. The toaster region uses role="region" with tabIndex="0" so keyboard users can move focus into the toast area. Non-visible toasts are marked with aria-hidden="true" and inert to prevent screen reader interaction.

Keyboard support#

KeyFunction
tabMoves focus into or out of the toast region.
enterActivates the focused toast action or close button.
spaceActivates the focused toast action or close button.