Getting Started
A beautiful and minimal toast notification library for Astro. Install once, use everywhere β no framework overhead, no opinions.
Installation
Install toastro using your preferred package manager:
# install the package
npm install toastro Setup
Add <Toaster /> once in your main layout. It manages
the notification queue and all animations automatically.
---
import { Toaster } from 'toastro';
---
<html lang="en">
<body>
<slot />
<Toaster />
</body>
</html> <Toaster /> defaults to position="bottom-right". See Positions for all options. Usage
Call window.showToast() from any client script. No imports
needed β it's globally available once <Toaster /> is
mounted.
<button id="btn">Show toast</button>
<script>
document.getElementById("btn").addEventListener("click", () => {
window.showToast({
message: "Hello from toastro π",
type: "success",
variant: "glass",
});
});
</script> Types
Use type to convey intent. Each type ships with a built-in
icon.
window.showToast({ message: "Saved!", type: "success" });
window.showToast({ message: "Something failed", type: "error" });
window.showToast({ message: "Watch out", type: "warning" });
window.showToast({ message: "Just so you know", type: "info" });
window.showToast({ message: "Plain message", type: "default" }); | Type | Icon | Use case |
|---|---|---|
default | Neutral messages | |
success | Completed actions | |
error | Failures, validation errors | |
warning | Non-critical alerts | |
info | Informational messages |
Variants
Control the visual style of each toast with variant.
window.showToast({ message: "Solid", type: "success", variant: "solid" });
window.showToast({ message: "Soft", type: "success", variant: "soft" });
window.showToast({ message: "Outline", type: "success", variant: "outline" });
window.showToast({ message: "Glass", type: "success", variant: "glass" }); | Variant | Description |
|---|---|
solid | Filled background, high contrast default |
soft | Subtle tint, low contrast |
outline | Transparent background with colored border |
glass | Frosted glass effect with backdrop blur |
Positions
Pass position to <Toaster /> to control
where toasts appear.
<Toaster position="bottom-right" /> <!-- default -->
<Toaster position="bottom-left" />
<Toaster position="bottom-center" />
<Toaster position="top-right" />
<Toaster position="top-left" />
<Toaster position="top-center" />
<Toaster position="center" /> Custom Icons
Pass a raw SVG string to override the default icon, or null to hide it entirely.
// Custom SVG icon
window.showToast({
message: "Deployed to production",
icon: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 19V5M5 12l7-7 7 7"/>
</svg>`,
});
// No icon
window.showToast({
message: "Clean, iconless toast",
icon: null,
}); Custom Colors
Solid color
Use color to set a custom accent that drives the icon, border,
and highlights.
window.showToast({
message: "Custom brand color",
color: "#6366f1",
}); Gradient
Pass an array of colors to gradientColors for a horizontal
gradient background.
window.showToast({
message: "Gradient toast π",
gradientColors: ["#f97316", "#ec4899", "#8b5cf6"],
}); Duration
Control how long (in ms) the toast stays visible. Defaults to 4000.
window.showToast({ message: "Quick!", duration: 1500 });
window.showToast({ message: "Lingersβ¦", duration: 8000 }); CSS Theming
Toastro uses CSS variables so it inherits your site's design system automatically. Override any of these in your global styles:
:root {
--toastro-bg: var(--bg); /* toast background */
--toastro-text: var(--text); /* text color */
--toastro-radius: 12px; /* border radius */
} API Reference
<Toaster /> props
| Prop | Type | Default | Description |
|---|---|---|---|
position | Position | "bottom-right" | Where toasts appear on screen |
type Position =
| "top-left" | "top-center" | "top-right"
| "bottom-left" | "bottom-center" | "bottom-right"
| "center"; showToast(options)
| Option | Type | Default | Description |
|---|---|---|---|
message | string | required | The text content of the toast |
type | ToastType | "default" | Controls icon and color theme |
variant | ToastVariant | "solid" | Visual style |
icon | string | null | undefined | Custom SVG string, or null to hide |
color | string | undefined | Custom CSS color for the accent |
gradientColors | string[] | undefined | Array of colors for gradient background |
duration | number | 4000 | Time in ms before auto-dismiss |
type ToastType = "default" | "success" | "error" | "warning" | "info";
type ToastVariant = "solid" | "soft" | "outline" | "glass";