Component Library

← Back to gallery

Offline queue alert in HTML, CSS and vanilla JS

A copy-paste Offline queue alert in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Feedback · Tags: alert, offline, queue, status

Live preview

Source (copy-ready)

<section class="dcl-alert-offline-queue" data-dcl-scheme="light" aria-label="Offline queue alert example">
<div data-row data-spread>
  <div data-stack>
    <h2>Drafts waiting to sync</h2>
    <p role="status"><strong>Offline.</strong> Two edits queued on this device in the demo.</p>
  </div>
  <button type="button" data-primary>Simulate reconnection</button>
</div>
<script>
(() => {
  const root = document.currentScript.closest(".dcl-alert-offline-queue");
  const preference = matchMedia("(prefers-color-scheme: dark)");
  const setTheme = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
  preference.addEventListener("change", setTheme);
  setTheme();
  const find = (selector) => root.querySelector(selector);
  const button = find("button");
  let offline = true;
  button.addEventListener("click", () => {
    offline = !offline;
    find('[role="status"]').textContent = offline ? "Offline. Two edits queued in this demo." : "Online. Both demo edits are synced.";
    button.textContent = offline ? "Simulate reconnection" : "Simulate going offline";
  });
})();
</script>
</section>
<style>
.dcl-alert-offline-queue, .dcl-alert-offline-queue * { box-sizing: border-box; }
.dcl-alert-offline-queue { font: 1rem/1.5 system-ui, sans-serif; max-inline-size: 40rem; padding: clamp(0.75rem, 3vw, 1.25rem); border: 1px solid; border-radius: 0.75rem; overflow-wrap: anywhere; }
.dcl-alert-offline-queue :where(h2, h3, p, ol, ul, dl, dd) { margin: 0; }
.dcl-alert-offline-queue h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-alert-offline-queue h3 { font-size: 1rem; }
.dcl-alert-offline-queue p + p { margin-block-start: 0.5rem; }
.dcl-alert-offline-queue [data-stack], .dcl-alert-offline-queue form { display: grid; gap: 0.75rem; }
.dcl-alert-offline-queue [data-row] { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dcl-alert-offline-queue [data-split] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem 1.25rem; align-items: start; }
.dcl-alert-offline-queue [data-spread] { justify-content: space-between; }
.dcl-alert-offline-queue [hidden] { display: none !important; }
.dcl-alert-offline-queue :where(button, summary, input, select) { font: inherit; }
.dcl-alert-offline-queue :where(button, input, select) { min-block-size: 44px; min-inline-size: 0; max-inline-size: 100%; }
.dcl-alert-offline-queue :where(button, input, select) { border: 1px solid; border-radius: 0.375rem; padding: 0.45rem 0.7rem; }
.dcl-alert-offline-queue :where(button, summary) { cursor: pointer; font-weight: 650; }
.dcl-alert-offline-queue :where(button, summary):active { box-shadow: inset 0 0 0 2px currentColor; }
.dcl-alert-offline-queue summary:hover { text-decoration: underline; }
.dcl-alert-offline-queue :where(button, input, select):disabled, .dcl-alert-offline-queue [aria-disabled=true] { cursor: not-allowed; border-style: dashed; }
.dcl-alert-offline-queue label { display: grid; gap: 0.25rem; }
.dcl-alert-offline-queue :where(input, select) { inline-size: 100%; }
.dcl-alert-offline-queue label[data-choice] { display: flex; gap: 0.5rem; align-items: center; min-block-size: 44px; }
.dcl-alert-offline-queue label[data-choice] input { inline-size: 1.25rem; block-size: 1.25rem; min-block-size: 0; flex-shrink: 0; }
.dcl-alert-offline-queue fieldset { min-inline-size: 0; margin: 0; border-radius: 0.375rem; padding: 0.5rem 0.75rem; }
.dcl-alert-offline-queue :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-alert-offline-queue[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-alert-offline-queue { color-scheme: light; border-color: #697f84; }
.dcl-alert-offline-queue { color: #11292f; background-color: #ffffff; }
.dcl-alert-offline-queue button, .dcl-alert-offline-queue input, .dcl-alert-offline-queue select { color: #11292f; background-color: #e4edef; }
.dcl-alert-offline-queue button[data-primary] { color: #ffffff; background-color: #00535a; }
.dcl-alert-offline-queue button:hover { color: #ffffff; background-color: #003c42; }
.dcl-alert-offline-queue button[disabled], .dcl-alert-offline-queue button[aria-disabled=true] { color: #405a60; background-color: #e4edef; }
.dcl-alert-offline-queue[data-dcl-scheme="dark"] { color-scheme: dark; border-color: #839fa5; }
.dcl-alert-offline-queue[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; }
.dcl-alert-offline-queue[data-dcl-scheme="dark"] button, .dcl-alert-offline-queue[data-dcl-scheme="dark"] input, .dcl-alert-offline-queue[data-dcl-scheme="dark"] select { color: #eff8f9; background-color: #1c3c44; }
.dcl-alert-offline-queue[data-dcl-scheme="dark"] button[data-primary] { color: #11292f; background-color: #8fe1da; }
.dcl-alert-offline-queue[data-dcl-scheme="dark"] button:hover { color: #11292f; background-color: #b2f2ec; }
.dcl-alert-offline-queue[data-dcl-scheme="dark"] button[disabled], .dcl-alert-offline-queue[data-dcl-scheme="dark"] button[aria-disabled=true] { color: #b0c9ce; background-color: #1c3c44; }
</style>

When to use

Keep a small alert in the editor while drafts wait in the offline queue.

Avoid

Do not promise queued edits survived a page reload unless the application persists them.

Accessibility

The connection label is a persistent live region and the simulated reconnection is a native button. Text contrast is at least 6.1:1 in light and 6.7:1 in dark.

Was this useful? Send feedback.