
notice.js is a dependency-free JavaScript toast notification library for stackable status messages with optional countdown progress bars.
It ships as browser, ESM, and CommonJS builds with TypeScript definitions, and the API works through direct status helpers or configurable NoticeJs instances.
Features
- Success, info, warning, and error notification types.
- 11 screen positions, including full-width top and bottom bars.
- Timed or persistent notices with optional countdown progress bars.
- Automatic timer pausing on hover, keyboard focus, and hidden browser tabs.
- Configurable button, click, and touch or pen swipe dismissal, plus Escape from a focused notice.
- Promise notices for loading, success, and error states.
- Action buttons with optional custom handlers.
- Programmatic updating, closing, pausing, resuming, and deduplication by ID.
- Configurable notice limits per position.
- Modal notices, RTL layout, and custom open or close animation classes.
- Plain-text rendering by default with opt-in HTML and a custom sanitizer hook.
- ARIA live regions, modal focus handling, and reduced-motion behavior.
- Theme customization through CSS custom properties.
How to use it
Direct browser setup
Load the stylesheet before the browser build:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notice.js@1/dist/noticejs.css"> <script src="https://cdn.jsdelivr.net/npm/notice.js@1/dist/notice.js"></script>
Use one of the static helpers for a basic toast:
NoticeJs.success('Profile saved');Create an instance when the notice needs custom content or behavior:
const notice = new NoticeJs({
title: 'Saved',
text: 'Your changes are live.',
type: 'success',
position: 'topRight',
timeout: 5000
}).show();npm and ESM
npm install notice.js
import { NoticeJs } from 'notice.js';
import 'notice.js/noticejs.css';
NoticeJs.info('New version available');Notification types
The four built-in type values are success, info, warning, and error. Static helpers are available for each type:
NoticeJs.success('Saved');
NoticeJs.info('New message');
NoticeJs.warning('Storage is almost full');
NoticeJs.error('Upload failed', { title: 'Error' });Promise notifications
NoticeJs.promise() creates a loading notice and updates it when the promise resolves or rejects. It returns the original promise.
const profilePromise = NoticeJs.promise(saveProfile(), {
loading: 'Saving profile...',
success: 'Profile saved',
error: (error) => ({
title: 'Save failed',
text: error.message
})
});Action buttons
new NoticeJs({
text: 'Email archived',
actions: [
{
label: 'Undo',
onClick: () => restoreEmail()
},
{
label: 'Details',
onClick: () => openDetails(),
closeOnClick: false
}
]
}).show();Action fields
| Action field | Description |
|---|---|
label | string, required. Button label. |
onClick | function, optional. Receives the notice instance and the click event. |
className | string, optional. Extra class names for the action button. |
closeOnClick | boolean, default true. Closes the notice after the action handler runs. |
Update, close, and deduplicate notices
Use a stable id to update an existing notice and avoid duplicate stacking.
const uploadNotice = new NoticeJs({
id: 'upload-status',
text: 'Uploading...',
timeout: false,
loading: true
}).show();
uploadNotice.update({
text: 'Upload complete',
type: 'success',
loading: false,
timeout: 3000
});
uploadNotice.close();
NoticeJs.get('upload-status')?.close();
NoticeJs.closeAll();
NoticeJs.closeAll('bottomRight');Global defaults
NoticeJs.overrideDefaults({
position: 'bottomRight',
timeout: 5000
});
NoticeJs.resetDefaults();Configuration options
new NoticeJs(options?) accepts one optional NoticeOptions object. Omitted values use the current global defaults.
Content and type
| Option | Type, default, and description |
|---|---|
id | string, auto-generated. Stable identifier used for deduplication and NoticeJs.get(). |
title | string, default ''. Heading text. |
text | string, default ''. Plain-text message rendered with textContent. |
html | string | Node | null, default null. Rich content used in place of text. String content uses the sanitize hook when one is set. |
sanitize | (html: string) => string | TrustedHTML, default null. Receives HTML strings before insertion. Supply a sanitizer for untrusted markup. |
type | 'success' | 'info' | 'warning' | 'error', default 'success'. Controls the status styling and default live-region behavior. |
loading | boolean, default false. Displays a spinner for pending work. |
className | string, default ''. Extra class names applied to the notice element. |
Timing and dismissal
| Option | Type, default, and description |
|---|---|
timeout | number | false, default 3000. Total display time in milliseconds. Use false for a persistent notice. |
progressBar | boolean, default true. Displays the countdown progress bar. |
closeWith | ('button' | 'click' | 'swipe')[], default ['button', 'swipe']. Selects close-button, whole-notice click, and touch or pen swipe dismissal. Escape can dismiss a focused notice. |
pauseOnHover | boolean, default true. Pauses the countdown when the pointer is over the notice or focus is inside it. |
pauseOnFocusLoss | boolean, default true. Pauses the countdown when the browser tab is hidden. |
Position, layout, and stacking
| Option | Type, default, and description |
|---|---|
position | NoticePosition, default 'topRight'. Selects one of the 11 documented positions. |
width | number | string | null, default 320. A number is interpreted as pixels. A string can use any CSS length. null uses the stylesheet width. The full-width top and bottom positions ignore this value. |
maxHeight | number | null, default null. Maximum body height in pixels before the content scrolls. |
newestOnTop | boolean, default false. Inserts newer notices before existing notices in the position container. |
maxVisible | number | null, default null. Limits visible notices at the selected position. Older notices close first. |
modal | boolean, default false. Dims the page and moves focus to the notice. |
rtl | boolean, default false. Uses right-to-left layout. |
animation | { open?, close? } | null, default null. CSS class names applied for enter and exit animations. |
Actions, accessibility, and callbacks
| Option | Type, default, and description |
|---|---|
actions | NoticeAction[], default []. Each action requires label and accepts onClick, className, and closeOnClick. closeOnClick defaults to true. |
ariaLive | 'polite' | 'assertive' | 'off'. Defaults to assertive for warning and error notices and polite for success and info notices. |
callbacks | { [event]: fn | fn[] }, default {}. Registers one function or an array of functions for each documented lifecycle callback. |
Available positions
top and bottom create full-width bars and display one notice at a time.
| Value | Location |
|---|---|
top | Full-width top bar. |
topLeft | Top left. |
topCenter | Top center. |
topRight | Top right. |
middleLeft | Middle left. |
middleCenter | Middle center. |
middleRight | Middle right. |
bottom | Full-width bottom bar. |
bottomLeft | Bottom left. |
bottomCenter | Bottom center. |
bottomRight | Bottom right. |
Instance API
position and modal cannot change after a notice has been shown. Set those options before show().
| Member | Description |
|---|---|
show() | Renders the notice and returns the instance. If a visible notice already uses a matching id, the existing notice is updated and returned. |
update(options) | Updates content or behavior, re-renders a visible notice, and restarts its countdown. |
close() | Closes the notice and returns a promise that resolves after removal. |
pause() | Pauses the countdown. |
resume() | Resumes a countdown paused through the API. |
on(event, fn) | Registers a callback and returns the instance. |
off(event, fn?) | Removes one callback or all callbacks registered for the event and returns the instance. |
element | The notice HTMLElement after show(), otherwise null. |
id | The stable notice ID. |
options | The resolved options for the instance. |
isVisible | Boolean state for a visible notice. |
Static API
| Member | Description |
|---|---|
NoticeJs.defaults | Reads the current global defaults. |
NoticeJs.overrideDefaults(options) | Changes defaults used by notices created afterward. |
NoticeJs.resetDefaults() | Restores the built-in defaults. |
NoticeJs.get(id) | Returns the visible notice with the supplied ID, if present. |
NoticeJs.closeAll(position?) | Closes all visible notices, or notices at one position. Returns a promise. |
NoticeJs.success(text, options?) | Shows a success notice. |
NoticeJs.error(text, options?) | Shows an error notice. |
NoticeJs.warning(text, options?) | Shows a warning notice. |
NoticeJs.info(text, options?) | Shows an info notice. |
NoticeJs.promise(input, messages, options?) | Shows a loading notice and updates it when a promise resolves or rejects. Returns the original promise. |
NoticeJs.promise() parameters
input accepts a promise or a function that returns a promise. options accepts the regular notice options used for the loading notice.
| Message field | Description |
|---|---|
loading | A string or NoticeOptions object for the pending state. |
success | A string, NoticeOptions object, or function that receives the resolved value and returns either form. |
error | A string, NoticeOptions object, or function that receives the rejected value and returns either form. |
Callbacks
Each callback receives the notice instance as its first argument and as this.
| Callback | Runs when |
|---|---|
beforeShow | Before the notice is inserted into its container. |
onShow | After the notice is inserted and marked visible. |
afterShow | After the open animation finishes. |
onClose | When closing begins. |
afterClose | After the notice has been removed. |
onClick | When the notice receives a click. |
onHover | When the pointer enters the notice. |
new NoticeJs({
text: 'Hello',
callbacks: {
afterClose: (notice) => {
console.log(`${notice.id} closed`);
}
}
}).show();Theme customization
Set the library’s CSS custom properties on :root to change the default theme:
:root {
--noticejs-success-bg: #0f766e;
--noticejs-success-accent: #115e59;
--noticejs-radius: 12px;
--noticejs-width: 360px;
--noticejs-font-family: Inter, sans-serif;
}Layout and shared theme variables
| Variable | Default and purpose |
|---|---|
--noticejs-font-family | System UI font stack. Notice font family. |
--noticejs-font-size | 14px. Base font size. |
--noticejs-width | 320px. Default notice width. |
--noticejs-offset | 12px. Distance from viewport edges. |
--noticejs-gap | 10px. Space between stacked notices. |
--noticejs-padding | 10px 12px. Heading and body padding. |
--noticejs-radius | 6px. Border radius. |
--noticejs-shadow | 0 6px 20px rgb(0 0 0 / 0.18). Notice box shadow. |
--noticejs-z-index | 10050. Notice container z-index. |
--noticejs-text | #fff. Notice text color. |
--noticejs-progress-height | 4px. Countdown bar height. |
--noticejs-focus-ring | 0 0 0 3px rgb(255 255 255 / 0.85). Focus ring shadow. |
Status and modal theme variables
| Variable | Default and purpose |
|---|---|
--noticejs-success-bg | #1f7a3d. Success background. |
--noticejs-success-accent | #176632. Success accent. |
--noticejs-info-bg | #0b62c4. Info background. |
--noticejs-info-accent | #0a4f9e. Info accent. |
--noticejs-warning-bg | #b54708. Warning background. |
--noticejs-warning-accent | #933a06. Warning accent. |
--noticejs-error-bg | #c62828. Error background. |
--noticejs-error-accent | #9f1f1f. Error accent. |
--noticejs-modal-bg | #000. Modal overlay color. |
--noticejs-modal-opacity | 0.35. Modal overlay opacity. |
--noticejs-modal-z-index | 10000. Modal overlay z-index. |
Upgrading from 0.5.x
timeoutis now the total display time in milliseconds. An old value of30becomes3000.textis always plain text. Usehtmlfor markup and a sanitizer for untrusted HTML strings.show()returns theNoticeJsinstance. Read the rendered element fromnotice.element.- The old
scrolloption is removed. UsemaxHeight. - The documented callback list contains seven lifecycle callbacks. The old
onTemplateentry is no longer part of the public callback API. - The default
closeWithvalue is now['button', 'swipe']. - The package ships plain CSS and no longer ships SCSS source files.
- IE11 is no longer supported. The JavaScript build targets ES2020.
Alternatives & Related Resources
- 10 Best Toast Notification JavaScript Libraries
- NotifyX: JavaScript Toast Notifications with AI Streaming
- Modern Toast Popup JavaScript Library – EggyJS
Changelog
v1.0.0 (09/26/2026)
- Rewritten in TypeScript with ESM, CommonJS, browser, and bundled type-definition outputs.
- Introduced promise notices, actions, update and close methods, ID deduplication, position limits, timer pausing, swipe dismissal, HTML sanitization hooks, and CSS custom properties.
- Added ARIA live regions, an accessible close button, Escape dismissal, modal focus handling, and reduced-motion behavior.
- Changed timeout semantics, text rendering, show return value, default dismissal methods, and browser baseline.
- Removed the old scroll option and SCSS package sources.
v0.5.0 (11/02/2025)
- Modernized the build setup and improved callback handling and documentation.







