GitHub

Toast

Notification toasts with auto-dismiss, severity variants, stacking, and server-side trigger helpers.

<rhx-toast>

Examples

Container Setup

Place a single <rhx-toast-container> in your layout. All toasts render inside it.

Trigger Toasts from Server

Click the buttons to trigger toasts via Response.HxToast() from the server.

Variants

This is a neutral notification.
New feature available!
Item saved successfully!
Your session expires in 5 minutes.
Failed to delete the item.

Server-Side: Event Trigger

The recommended approach. Sets HX-Trigger-After-Settle header; JavaScript creates the toast.

// In your Razor Page handler:
public IActionResult OnPostSave()
{
    // ... save logic ...
    Response.HxToast("Changes saved!", "success");
    return Partial("_Form", Model);
}

// Or with a custom duration:
Response.HxToast("Processing...", "brand", duration: 8000);

Server-Side: OOB Swap

For custom toast content. Server renders the full <rhx-toast> HTML and swaps it into the container.

// Return a toast via out-of-band swap:
public IActionResult OnPostDelete()
{
    // ... delete logic ...
    return this.HxToastOob("Item deleted", "danger", duration: 3000);
}

Container Properties

Properties for <rhx-toast-container>:

Properties

Property Type Default Description
rhx-position string top-end Position on screen: top-start, top-center, top-end, bottom-start, bottom-center, bottom-end
rhx-max int 5 Maximum number of toasts shown simultaneously
rhx-duration int 5000 Default auto-dismiss duration in milliseconds (0 = no auto-dismiss)

Toast Properties

Properties for <rhx-toast>:

Properties

Property Type Default Description
rhx-variant string neutral Color variant: neutral, brand, success, warning, danger
rhx-closable bool true Show a close/dismiss button
rhx-duration int? - Auto-dismiss duration in ms (overrides container default, 0 = no auto-dismiss)
rhx-icon string - Override the default icon for the variant

Accessibility

  • Toast container uses role="status" with aria-live="polite" so new toasts are announced without interrupting.
  • Close button has aria-label="Close" for screen readers.
  • Icons are marked aria-hidden="true" since variant meaning is conveyed through text content.
  • Auto-dismiss pauses on hover so users have time to read.
  • Animations respect prefers-reduced-motion.