Ship faster with goilerplate templUI Pro

Toast

Flexible toast component for notifications and feedback.

Source Tailwind CSS JavaScript

Installation

templui add toast

Load the script once in your layout:

<head>
  @toast.Script()
</head>
// Template
templ UserForm() {
	<form hx-post="/save" hx-target="#toast">
	   <input name="email" />
	</form>
	<div id="toast"></div>
}
// Handler
func Save(w http.ResponseWriter, r *http.Request) {
	if err != nil {
		toast.Toast(toast.Props{
			Description: err.Error(),
			Variant:     toast.VariantError,
		}).Render(r.Context(), w)
	}
}

Examples

Playground

Default
Success
Error
Warning
Info
Top Right
Top Left
Top Center
Bottom Right
Bottom Left
Bottom Center

API Reference

Required parameter
Hover for description

Toast

Notification component that appears temporarily to provide feedback.

Name Type Default
ID

Unique identifier for the toast element. Auto-generated if not provided.

string
-
Class

Additional CSS classes to apply to the toast.

string
-
Attributes

Additional HTML attributes to apply to the toast element.

templ.Attributes
-
Title

Title text displayed in the toast header.

string
-
Description

Description text displayed below the title.

string
-
Variant

Visual style variant. Options: 'default', 'success', 'error', 'warning', 'info'.

Variant
default
Position

Screen position for the toast. Options: 'top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center'.

Position
bottom-right
Duration

Duration in milliseconds before auto-dismissing the toast.

int
3000
Dismissible

Whether to show a close button for manual dismissal.

bool
false
ShowIndicator

Whether to show a progress indicator bar at the top.

bool
false
Icon

Whether to show an icon based on the variant type.

bool
false
Axel Adrian