Saved Notice in HTML, CSS and vanilla JS
A copy-paste Saved Notice in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="example-saved-notice" data-dcl-layout="stack" data-dcl-scheme="light" aria-labelledby="example-saved-notice-title"><header><h2 id="example-saved-notice-title">Saved Notice</h2></header><div class="parts"><button type="button" data-post>Show notification</button><div data-message><div role="status" aria-atomic="true"></div><button type="button" data-dismiss hidden>Dismiss</button></div><template><strong>Draft saved</strong><p>The latest edits are available in your workspace.</p><p><strong>Where</strong> Look in Recent drafts.</p></template></div>
<script>
(() => {
const root = document.currentScript.closest(".example-saved-notice");
const instance = Array.from(document.getElementsByClassName("example-saved-notice")).indexOf(root);
if (instance > 0) {
const references = ["id", "aria-labelledby", "aria-controls", "aria-describedby", "for", "name"];
for (const element of [root, ...root.querySelectorAll("*")]) {
for (const attr of references) {
if (element.hasAttribute(attr)) element.setAttribute(attr, element.getAttribute(attr) + "--" + instance);
}
const href = element.getAttribute("href");
if (href && href.startsWith("#")) element.setAttribute("href", href + "--" + instance);
}
}
const preference = matchMedia("(prefers-color-scheme: dark)");
const apply = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
preference.addEventListener("change", apply);
apply();
const message = root.querySelector("[data-message]");
const status = message.querySelector('[role="status"]');
const close = message.querySelector("[data-dismiss]");
const trigger = root.querySelector("[data-post]");
const template = root.querySelector("template");
function dismiss() {
status.replaceChildren();
message.removeAttribute("data-note");
close.hidden = true;
trigger.focus();
}
trigger.addEventListener("click", () => {
message.setAttribute("data-note", "");
close.hidden = false;
status.replaceChildren(template.content.cloneNode(true));
});
close.addEventListener("click", dismiss);
root.addEventListener("keydown", (event) => {
if (event.key === "Escape" && !close.hidden) dismiss();
});
})();
</script></section>
<style>
.example-saved-notice { color: #11292f; background-color: #ffffff; color-scheme: light; }
.example-saved-notice a { color: #005c62; }
.example-saved-notice button, .example-saved-notice summary, .example-saved-notice input, .example-saved-notice select {
color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.example-saved-notice button:hover, .example-saved-notice summary:hover, .example-saved-notice button[aria-selected="true"] {
color: #ffffff; background-color: #00535a;
}
.example-saved-notice dialog { color: #11292f; background-color: #ffffff; }
.example-saved-notice [data-note] { color: #11292f; background-color: #e4edef; }
.example-saved-notice :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.example-saved-notice[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.example-saved-notice[data-dcl-scheme="dark"] a { color: #8fe1da; }
.example-saved-notice[data-dcl-scheme="dark"] button, .example-saved-notice[data-dcl-scheme="dark"] summary, .example-saved-notice[data-dcl-scheme="dark"] input, .example-saved-notice[data-dcl-scheme="dark"] select {
color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.example-saved-notice[data-dcl-scheme="dark"] button:hover, .example-saved-notice[data-dcl-scheme="dark"] summary:hover, .example-saved-notice[data-dcl-scheme="dark"] button[aria-selected="true"] {
color: #11292f; background-color: #8fe1da;
}
.example-saved-notice[data-dcl-scheme="dark"] dialog { color: #eff8f9; background-color: #142f36; }
.example-saved-notice[data-dcl-scheme="dark"] [data-note] { color: #eff8f9; background-color: #1c3c44; }
.example-saved-notice[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.example-saved-notice, .example-saved-notice * { box-sizing: border-box; }
.example-saved-notice { font: 1rem/1.5 system-ui, sans-serif; padding: 1rem; border-radius: 0.75rem; overflow-wrap: anywhere; }
.example-saved-notice h2, .example-saved-notice h3 { line-height: 1.15; margin-block: 0 0.75rem; }
.example-saved-notice p { margin-block: 0.5rem; }
.example-saved-notice ul { margin-block: 0.5rem; padding-inline-start: 1.5rem; }
.example-saved-notice article, .example-saved-notice details, .example-saved-notice [data-note] { border: 1px solid; border-radius: 0.375rem; padding: 0.75rem; }
.example-saved-notice button, .example-saved-notice summary, .example-saved-notice input, .example-saved-notice select {
min-block-size: 44px; border: 1px solid; border-radius: 0.375rem; padding: 0.5rem 0.75rem; font: inherit;
}
.example-saved-notice button, .example-saved-notice summary { cursor: pointer; transition: background-color 140ms ease-out; }
.example-saved-notice button:disabled { cursor: not-allowed; text-decoration: line-through; }
.example-saved-notice input { display: block; inline-size: 100%; }
.example-saved-notice dialog { max-inline-size: min(32rem, 90vw); border-radius: 0.75rem; padding: 1rem; }
.example-saved-notice th, .example-saved-notice td { padding: 0.5rem; text-align: start; border-block-end: 1px solid; }
.example-saved-notice table { border-collapse: collapse; inline-size: 100%; }
.example-saved-notice caption { font-weight: bold; text-align: start; }
.example-saved-notice dt { font-weight: 600; }
.example-saved-notice dd { margin: 0 0 0.75rem; }
.example-saved-notice [hidden] { display: none !important; }
.example-saved-notice .parts { display: grid; gap: 1rem; }
@media (max-width: 30rem) {
.example-saved-notice[data-dcl-layout="rail"] .parts { grid-template-columns: minmax(0, 1fr); }
.example-saved-notice[data-dcl-layout="rail"] .parts > :is(p, ul, article) { grid-column: 1; grid-row: auto; }
.example-saved-notice[data-dcl-layout="rail"] .parts > :is(details, nav) { grid-row: auto; }
}
@media (prefers-reduced-motion: reduce) { .example-saved-notice * { transition: none !important; } }
</style>
When to use
Use this stacked pattern to give each item a full-width row.
Avoid
Use a persistent inline error for anything that needs immediate correction.
Accessibility
Update a polite status region without moving focus; provide a keyboard-accessible dismiss action.
Was this useful? Send feedback.