Component Library

← Back to gallery

Queue toast stack in HTML, CSS and vanilla JS

A copy-paste Queue toast stack in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Feedback · Tags: toast, queue, stack, dismissible

Live preview

Source (copy-ready)

<section class="dcl-queue-toast-stack" data-dcl-scheme="light" aria-labelledby="dcl-queue-toast-stack-title"><header class="dcl-queue-toast-stack__header"><h2 id="dcl-queue-toast-stack-title">Queue toast stack</h2><p class="dcl-queue-toast-stack__muted">Multiple bounded notifications stack newest-first with independent dismissal.</p></header><button type="button" data-add>Post backup notice</button><button type="button" data-add-sync>Post sync notice</button><div class="dcl-queue-toast-stack__stack" aria-live="polite" aria-label="Notifications" data-stack></div><script>(()=>{const root=document.currentScript.closest(".dcl-queue-toast-stack");if(!root||root.dataset.dclBound)return;root.dataset.dclBound="1";const instance=Array.from(document.getElementsByClassName("dcl-queue-toast-stack")).indexOf(root);if(instance>0){for(const el of [root,...root.querySelectorAll("*")]){for(const attr of ["id","aria-labelledby","aria-controls","aria-describedby","for","name"]){if(el.hasAttribute(attr))el.setAttribute(attr,el.getAttribute(attr)+"--"+instance)}const href=el.getAttribute("href");if(href&&href.startsWith("#"))el.setAttribute("href",href+"--"+instance)}}const preference=matchMedia("(prefers-color-scheme: dark)"),apply=()=>{root.dataset.dclScheme=preference.matches?"dark":"light"};preference.addEventListener("change",apply);apply();const q=(s)=>root.querySelector(s),qa=(s)=>Array.from(root.querySelectorAll(s));const stack=q("[data-stack]");function add(text){const item=document.createElement("div");item.className=root.className+"__toast";const p=document.createElement("p");p.textContent=text;const b=document.createElement("button");b.type="button";b.textContent="Dismiss";b.addEventListener("click",()=>item.remove());item.append(p,b);stack.prepend(item);while(stack.children.length>3)stack.lastElementChild.remove()}q("[data-add]").addEventListener("click",()=>add("Backup finished"));q("[data-add-sync]").addEventListener("click",()=>add("Sync resumed"));})();</script></section>
<style>
.dcl-queue-toast-stack{color:#11292f;background-color:#ffffff;color-scheme:light;font:1rem/1.45 system-ui,sans-serif;padding:.8rem;border:1px solid #697f84;border-radius:.6rem;overflow-wrap:anywhere}
.dcl-queue-toast-stack *{box-sizing:border-box}.dcl-queue-toast-stack h2,.dcl-queue-toast-stack h3{line-height:1.15;margin-block:0 .6rem}.dcl-queue-toast-stack a{color:#005c62}
.dcl-queue-toast-stack button,.dcl-queue-toast-stack input,.dcl-queue-toast-stack select,.dcl-queue-toast-stack textarea,.dcl-queue-toast-stack summary{min-block-size:44px;border:1px solid #697f84;border-radius:.3rem;padding:.4rem .65rem;font:inherit;color:#11292f;background-color:#e4edef}
.dcl-queue-toast-stack input,.dcl-queue-toast-stack select,.dcl-queue-toast-stack textarea{background-color:#ffffff}.dcl-queue-toast-stack input[type="radio"],.dcl-queue-toast-stack input[type="checkbox"]{min-block-size:auto;inline-size:auto}
.dcl-queue-toast-stack button,.dcl-queue-toast-stack summary{cursor:pointer}.dcl-queue-toast-stack button:hover,.dcl-queue-toast-stack summary:hover{color:#ffffff;background-color:#00535a}
.dcl-queue-toast-stack button:focus-visible,.dcl-queue-toast-stack input:focus-visible,.dcl-queue-toast-stack select:focus-visible,.dcl-queue-toast-stack textarea:focus-visible,.dcl-queue-toast-stack summary:focus-visible,.dcl-queue-toast-stack a:focus-visible{outline:3px solid #005c62;outline-offset:2px}
.dcl-queue-toast-stack details{color:#11292f;background-color:#ffffff;border:1px solid #697f84;border-radius:.4rem;margin-block-start:.6rem}.dcl-queue-toast-stack summary{font-weight:650}
.dcl-queue-toast-stack dialog{color:#11292f;background-color:#ffffff;border:1px solid #697f84;border-radius:.6rem;max-inline-size:min(34rem,92vw);padding:1rem}
.dcl-queue-toast-stack table{border-collapse:collapse;inline-size:100%;color:#11292f;background-color:#ffffff}.dcl-queue-toast-stack th,.dcl-queue-toast-stack td{padding:.4rem;text-align:start;border-block-end:1px solid #697f84}.dcl-queue-toast-stack th{color:#11292f;background-color:#e4edef}
.dcl-queue-toast-stack [hidden]{display:none!important}.dcl-queue-toast-stack__muted{color:#405a60}.dcl-queue-toast-stack__panel{color:#405a60;background-color:#ffffff}.dcl-queue-toast-stack__well{color:#11292f;background-color:#e4edef}.dcl-queue-toast-stack__primary,.dcl-queue-toast-stack__badge{color:#ffffff;background-color:#00535a}.dcl-queue-toast-stack__badge{border-radius:999px;padding:.1rem .45rem;font-size:.8rem;font-weight:700}
.dcl-queue-toast-stack[data-dcl-scheme="dark"]{color:#eff8f9;background-color:#142f36;color-scheme:dark;border-color:#839fa5}.dcl-queue-toast-stack[data-dcl-scheme="dark"] a{color:#8fe1da}
.dcl-queue-toast-stack[data-dcl-scheme="dark"] button,.dcl-queue-toast-stack[data-dcl-scheme="dark"] input,.dcl-queue-toast-stack[data-dcl-scheme="dark"] select,.dcl-queue-toast-stack[data-dcl-scheme="dark"] textarea,.dcl-queue-toast-stack[data-dcl-scheme="dark"] summary{color:#eff8f9;background-color:#1c3c44;border-color:#839fa5}
.dcl-queue-toast-stack[data-dcl-scheme="dark"] input,.dcl-queue-toast-stack[data-dcl-scheme="dark"] select,.dcl-queue-toast-stack[data-dcl-scheme="dark"] textarea{background-color:#142f36}.dcl-queue-toast-stack[data-dcl-scheme="dark"] button:hover,.dcl-queue-toast-stack[data-dcl-scheme="dark"] summary:hover{color:#11292f;background-color:#8fe1da}
.dcl-queue-toast-stack[data-dcl-scheme="dark"] button:focus-visible,.dcl-queue-toast-stack[data-dcl-scheme="dark"] input:focus-visible,.dcl-queue-toast-stack[data-dcl-scheme="dark"] select:focus-visible,.dcl-queue-toast-stack[data-dcl-scheme="dark"] textarea:focus-visible,.dcl-queue-toast-stack[data-dcl-scheme="dark"] summary:focus-visible,.dcl-queue-toast-stack[data-dcl-scheme="dark"] a:focus-visible{outline-color:#8fe1da}
.dcl-queue-toast-stack[data-dcl-scheme="dark"] details,.dcl-queue-toast-stack[data-dcl-scheme="dark"] dialog,.dcl-queue-toast-stack[data-dcl-scheme="dark"] table{color:#eff8f9;background-color:#142f36;border-color:#839fa5}.dcl-queue-toast-stack[data-dcl-scheme="dark"] th{color:#eff8f9;background-color:#1c3c44}.dcl-queue-toast-stack[data-dcl-scheme="dark"] th,.dcl-queue-toast-stack[data-dcl-scheme="dark"] td{border-color:#839fa5}
.dcl-queue-toast-stack[data-dcl-scheme="dark"] .dcl-queue-toast-stack__muted{color:#b0c9ce}.dcl-queue-toast-stack[data-dcl-scheme="dark"] .dcl-queue-toast-stack__panel{color:#b0c9ce;background-color:#142f36}.dcl-queue-toast-stack[data-dcl-scheme="dark"] .dcl-queue-toast-stack__well{color:#eff8f9;background-color:#1c3c44}.dcl-queue-toast-stack[data-dcl-scheme="dark"] .dcl-queue-toast-stack__primary,.dcl-queue-toast-stack[data-dcl-scheme="dark"] .dcl-queue-toast-stack__badge{color:#11292f;background-color:#8fe1da}
@media (prefers-reduced-motion:reduce){.dcl-queue-toast-stack *{transition:none!important;animation:none!important}}
.dcl-queue-toast-stack__stack{position:relative;display:grid;gap:.5rem;margin-block-start:1rem}.dcl-queue-toast-stack__toast{display:flex;justify-content:space-between;gap:1rem;border:1px solid #697f84;border-radius:.45rem;padding:.65rem;color:#11292f;background-color:#e4edef}.dcl-queue-toast-stack[data-dcl-scheme="dark"] .dcl-queue-toast-stack__toast{color:#eff8f9;background-color:#1c3c44}</style>

When to use

Use when several transient background events can arrive close together. Cap the visible stack so controls remain reachable.

Avoid

Do not let multiple toasts cover primary content or continue accumulating without a bound.

Accessibility

Notifications are inserted into a polite live stack with real dismiss buttons, and older entries are removed in DOM order rather than hidden by colour. Status text is written text rather than colour alone and focus is visibly outlined. Light text is #11292f or #405a60 on the surface (15.19:1/7.37:1); dark text is #eff8f9 or #b0c9ce on the dark surface (13.07:1/8.12:1).

Was this useful? Send feedback.