Toast
A message that appears on the screen to provide feedback on an action.
A message that appears on the screen to provide feedback on an action.
To set up the toast correctly, you’ll need to understand its anatomy and how we name its parts.
Each part includes a
data-partattribute to help identify them in the DOM.
To use the Toast component in your application, you need to set it up using the
createToaster hook. This hook manages the placement and grouping of toasts,
and provides a toast object needed to create toast notification.
To create a basic Toast, use the toast.create method to display a
notification.
import { Toast, createToaster } from '@ark-ui/react'
const Basic = () => {
  const [Toaster, toast] = createToaster({
    placement: 'top-end',
    render(toast) {
      return (
        <Toast.Root>
          <Toast.Title>{toast.title}</Toast.Title>
          <Toast.Description>{toast.description}</Toast.Description>
          <Toast.CloseTrigger>Close</Toast.CloseTrigger>
        </Toast.Root>
      )
    },
  })
  return (
    <>
      <button onClick={() => toast.create({ title: 'Title', description: 'Description' })}>
        Toast
      </button>
      <Toaster />
    </>
  )
}
import { Toast, createToaster } from '@ark-ui/solid'
const Basic = () => {
  const [Toaster, toast] = createToaster({
    placement: 'top-end',
    render(toast) {
      return (
        <Toast.Root>
          <Toast.Title>{toast().title}</Toast.Title>
          <Toast.Description>{toast().description}</Toast.Description>
          <Toast.CloseTrigger>Close</Toast.CloseTrigger>
        </Toast.Root>
      )
    },
  })
  return (
    <>
      <button onClick={() => toast().create({ title: 'Title', description: 'Description' })}>
        Toast
      </button>
      <Toaster />
    </>
  )
}
<script setup lang="ts">
null
</script>
<template><button @click="createBasicToast">Toast</button> <BasicToaster /></template>
To configure the Toast component, you can pass various options to the
toast.create method. These options include title, description, type,
duration, and removeDelay:
import { Toast, createToaster } from '@ark-ui/react'
const Customized = () => {
  const [Toaster, toast] = createToaster({
    placement: 'bottom-start',
    render(toast) {
      return (
        <Toast.Root>
          <Toast.Title>{toast.title}</Toast.Title>
          <Toast.Description>{toast.description}</Toast.Description>
          <Toast.CloseTrigger>Close</Toast.CloseTrigger>
        </Toast.Root>
      )
    },
  })
  return (
    <>
      <button
        onClick={() =>
          toast.create({
            title: 'Success',
            description: 'This is a success toast',
            type: 'success',
            duration: 20000,
            removeDelay: 250,
          })
        }
      >
        Toast
      </button>
      <Toaster />
    </>
  )
}
import { Toast, createToaster } from '@ark-ui/solid'
const Customized = () => {
  const [Toaster, toast] = createToaster({
    placement: 'bottom-start',
    render(toast) {
      return (
        <Toast.Root>
          <Toast.Title>{toast().title}</Toast.Title>
          <Toast.Description>{toast().description}</Toast.Description>
          <Toast.CloseTrigger>Close</Toast.CloseTrigger>
        </Toast.Root>
      )
    },
  })
  return (
    <>
      <button
        onClick={() =>
          toast().create({
            title: 'Success',
            description: 'This is a success toast',
            type: 'success',
            duration: 20000,
            removeDelay: 250,
          })
        }
      >
        Toast
      </button>
      <Toaster />
    </>
  )
}
<script setup lang="ts">
null
</script>
<template><button @click="createCustomizedToast">Toast</button> <CustomizedToaster /></template>
For cases where you need more flexibility in rendering, the Toast component offers the ability to use a custom render function. This allows you to customize the content of the toast:
import { Toast, createToaster } from '@ark-ui/react'
const CustomRender = () => {
  const [Toaster, toast] = createToaster({
    placement: 'top-end',
    // custom render may go directly into the function below
    render(toast) {
      return (
        <Toast.Root>
          <Toast.Title>{toast.title}</Toast.Title>
          <Toast.Description>{toast.description}</Toast.Description>
          <Toast.CloseTrigger>Close</Toast.CloseTrigger>
        </Toast.Root>
      )
    },
  })
  return (
    <>
      <button
        onClick={() =>
          toast.create({
            title: 'Please checkout',
            render: (toast) => (
              <div>
                {toast.title} <a href="https://ark-ui.com">Ark UI</a>
              </div>
            ),
          })
        }
      >
        Toast
      </button>
      <Toaster />
    </>
  )
}
import { Toast, createToaster } from '@ark-ui/solid'
const CustomRender = () => {
  const [Toaster, toast] = createToaster({
    placement: 'top-end',
    // custom render may go directly into the function below
    render(toast) {
      return (
        <Toast.Root>
          <Toast.Title>{toast().title}</Toast.Title>
          <Toast.Description>{toast().description}</Toast.Description>
          <Toast.CloseTrigger>Close</Toast.CloseTrigger>
        </Toast.Root>
      )
    },
  })
  return (
    <>
      <button
        onClick={() =>
          toast().create({
            title: 'Please checkout',
            render: (toast) => (
              <div>
                {toast().title} <a href="https://ark-ui.com">Ark UI</a>
              </div>
            ),
          })
        }
      >
        Toast
      </button>
      <Toaster />
    </>
  )
}
<script setup lang="ts">
null
</script>
<template><button @click="createCustomRenderToast">Toast</button> <CustomRenderToaster /></template>
| Prop | Type | Default | 
|---|---|---|
| asChildRender as a different element type. | boolean | 
| Prop | Type | Default | 
|---|---|---|
| asChildRender as a different element type. | boolean | 
| Prop | Type | Default | 
|---|---|---|
| asChildRender as a different element type. | boolean | 
| Prop | Type | Default | 
|---|---|---|
| placementThe placement of the toast | Placement | |
| render | (api: MachineApi<PropTypes>) => Element | |
| count | number | |
| dirThe document's text/writing direction. | 'ltr' | 'rtl' | "ltr" | 
| docThe owner document of the machine. | Document | |
| durationThe duration the toast will be visible | number | |
| getRootNodeA root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
| gutterThe gutter or spacing between toasts | string | |
| idThe unique identifier of the machine. | string | |
| maxThe maximum number of toasts that can be shown at once | number | |
| offsetsThe offset from the safe environment edge of the viewport | string | Record<'left' | 'right' | 'top' | 'bottom', string> | |
| pauseOnInteractionWhether to pause the toast when interacted with | boolean | |
| pauseOnPageIdleWhether to pause toast when the user leaves the browser tab | boolean | |
| pointerdownNodeThe related target when the element is blurred. Used as a polyfill for `e.relatedTarget` | HTMLElement | |
| removeDelayThe duration for the toast to kept alive before it is removed. Useful for exit transitions. | number | |
| rootNodeThe root node of the machine. Useful for shadow DOM. | ShadowRoot | |
| zIndexThe z-index applied to each toast group | number | 
| Prop | Type | Default | 
|---|---|---|
| asChildRender as a different element type. | boolean | 
| Prop | Type | Default | 
|---|---|---|
| asChildRender as a different element type. | boolean | 
Previous
Tags InputNext
Toggle Group