Categories: CSSScriptWeb Design

Developer-Friendly Toast Alerts in JavaScript – Toast-JS

Toast-JS is a JavaScript notification library that provides a simple way to display non-blocking notification messages (toasts) in your web application.

Features:

  • 12+ positioning options (top/bottom/center combinations)
  • Prebuilt styles for success, error, warning, and info notifications
  • CSS-in-JS styling for custom designs without extra stylesheets
  • Dynamic icon support (SVG, PNG, even WebM/MP4 videos)
  • 15+ built-in animations (slide, fade, wobble, wave effects)
  • Duration control down to the millisecond
  • Accessible by default with proper ARIA attributes
  • React-compatible without additional dependencies

How to use it:

1. Include the library script ‘Toast.js’ on the webpage.

<script src="Toast.js"></script>

2. You need a container element where the toasts will appear.

<div id="toast-notification" class="toast-notification"></div>

3. Create a simple toast notification with the following code:

  • context: Target container.
  • message: The text content of the toast.
  • duration: How long the toast stays visible. Use Toast.LENGTH_SHORT (3 seconds), Toast.LENGTH_LONG (6 seconds), or provide milliseconds (e.g., 5000 for 5 seconds).
Toast.makeText(document.body, "CSSScript", Toast.LENGTH_SHORT).show();

4. You can then chain methods after makeText() before calling show():

Method Description Default
setStyle() Predefined or custom CSS object STYLE_DEFAULT
setPosition() One of 12 screen positions POSITION_BOTTOM_RIGHT
setAnimation() Entrance/exit animation pair FADE
setIcon() URL or data URI for icon None
setDismissible() Show close button false
setDuration() Milliseconds to display 3000 (LENGTH_SHORT)

Available Styles:

Toast.STYLE_SUCCESS, Toast.STYLE_ERROR, Toast.STYLE_INFO, Toast.STYLE_WARNING, Toast.STYLE_DEFAULT_1, Toast.STYLE_DEFAULT_2, Toast.STYLE_LIGHT_MODE, etc. You can also pass the string name like "success".

Sponsored

Available Positions:

Toast.POSITION_TOP_LEFT, Toast.POSITION_TOP_CENTER, Toast.POSITION_TOP_RIGHT, Toast.POSITION_BOTTOM_LEFT, Toast.POSITION_BOTTOM_CENTER, Toast.POSITION_BOTTOM_RIGHT, Toast.POSITION_CENTER

5. You can use Toast-JS in React, but it’s not a typical React library. It directly manipulates the DOM outside of React’s virtual DOM.

import React from 'react';
function MyComponent() {
  const handleShowToast = () => {
    // Check if Toast is loaded (good practice)
    if (window.Toast) {
      const toast = Toast.makeText(
        document.body, // Still use document.body
        "Hello from React!",
        Toast.LENGTH_SHORT
      );
      toast.setStyle(Toast.STYLE_INFO);
      toast.setPosition(Toast.POSITION_BOTTOM_RIGHT);
      toast.show();
    } else {
      console.error("Toast-JS library not loaded.");
    }
  };
  return (
    <button onClick={handleShowToast}>Show React Toast</button>
  );
}
export default MyComponent;

Changelog:

03/14/2026

  • v2.1.0beta

The post Developer-Friendly Toast Alerts in JavaScript – Toast-JS appeared first on CSS Script.

rssfeeds-admin

Share
Published by
rssfeeds-admin

Recent Posts

Canterbury town meeting progresses with congeniality, efficiency and some humor

Jostling a folded piece of paper, holding it marooned in the air, selectman Beth Blair…

2 hours ago

Boscawen voters address bus service concerns

Boscawen voters cruised through a speedy town meeting Friday night, one with so little controversy…

2 hours ago

Hulu, Disney Plus, and the Pixel Watch 4 are among this week’s best deals

Happy Saturday, all! This week, we found a number of deals that should help you…

3 hours ago

Prediction markets want the Oscars to be your gateway drug to betting on everything

Though it was weird to see the Golden Globes partner with Polymarket for its most…

4 hours ago

MacBook Air M5 review: a small update for the ‘just right’ Mac

Neo to the left of me. Pros are to the right. | Photo: Antonio G.…

4 hours ago

Zendesk to acquire Forethought AI to drive autonomous AI agents

Zendesk is to acquire Forethought AI. It says that this will be its largest acquisition…

4 hours ago

This website uses cookies.