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 component API with two component groups: Toaster (Root, Portal, Region) and Toast (Root, Icon, Title, Description, Action, Close)
  • Global toast function with variant methods (success, danger, warn, info, loading, custom, promise)
  • Built-in swipe-to-dismiss with directional detection
  • Stacked toast 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.Icon />
                        <Toast.Title />
                        <Toast.Description />
                        <Toast.Action />
                        <Toast.Close />
                    </Toast.Root>
                ))
            }
        </Toaster.Region>
    </Toaster.Portal>
</Toaster.Root>

Behavior#

Polymorphic Rendering#

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

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

Default elements: Toaster.Root=div, Toaster.Region=div, Toast.Root=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, providing access to 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
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
richColorsbooleanfalse
Whether to show rich colors
iconsPartial<Record<ToastVariant, ReactNode>>{}
Custom icons for each toast variant
[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

The Toaster.Region element sets CSS custom properties on its style for toast layout spacing.

CSS 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-variantToast variant (success, danger, etc.)
data-indexToast index in the stack
data-idToast identifier
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
data-rich-colorsPresent when rich colors are enabled

CSS Custom Properties

The Toast.Root element sets CSS custom properties on its style for swipe gestures and stacked positioning.

CSS 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.
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.

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.
AttributeValue
data-variantToast variant (success, danger, etc.)

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.
AttributeValue
data-variantToast variant (success, danger, etc.)

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.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-variantToast variant (success, danger, etc.)

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.
AttributeValue
data-variantToast variant (success, danger, etc.)

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.
AttributeValue
data-variantToast variant (success, danger, etc.)

Defines passthrough(pt) options of ToastClose component.

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

ToastRegion#

ToastItem#

Accessibility#

Screen Reader#

Toast uses role="alert" which implicitly sets aria-live to assertive and aria-atomic to true, ensuring screen readers announce toast content immediately. The toaster region uses role="region" with tabIndex="0" to allow keyboard navigation to 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.