Component Library

← Back to gallery

Handoff Dialog in HTML, CSS and vanilla JS

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

Category: Feedback · Tags: modal dialog, split, modal, dialog

Live preview

Source (copy-ready)

<section class="example-handoff-dialog" data-dcl-layout="split" data-dcl-scheme="light" aria-labelledby="example-handoff-dialog-title"><header><h2 id="example-handoff-dialog-title">Handoff Dialog</h2></header><div class="parts"><button type="button" data-open-dialog>Review handoff</button><dialog aria-labelledby="example-handoff-dialog-dialog-title"><h3 id="example-handoff-dialog-dialog-title">Review handoff</h3><div class="dialog-parts"><p>Read the handoff before joining the project.</p><dl data-note><dt>Maintainer</dt><dd>The frontend working group.</dd><dt>Review window</dt><dd>Two business days.</dd></dl></div><div class="dialog-actions"><button type="button" data-close-dialog autofocus>Close</button></div></dialog></div>
<script>
(() => {
  const root = document.currentScript.closest(".example-handoff-dialog");
  const instance = Array.from(document.getElementsByClassName("example-handoff-dialog")).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 dialog = root.querySelector("dialog");
  const open = root.querySelector("[data-open-dialog]");
  open.addEventListener("click", () => dialog.showModal());
  dialog.querySelector("[data-close-dialog]").addEventListener("click", () => dialog.close());
  dialog.addEventListener("close", () => open.focus());

})();
</script></section>
<style>

.example-handoff-dialog { color: #11292f; background-color: #ffffff; color-scheme: light; }
.example-handoff-dialog a { color: #005c62; }
.example-handoff-dialog button, .example-handoff-dialog summary, .example-handoff-dialog input, .example-handoff-dialog select {
  color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.example-handoff-dialog button:hover, .example-handoff-dialog summary:hover, .example-handoff-dialog button[aria-selected="true"] {
  color: #ffffff; background-color: #00535a;
}
.example-handoff-dialog dialog { color: #11292f; background-color: #ffffff; }
.example-handoff-dialog [data-note] { color: #11292f; background-color: #e4edef; }
.example-handoff-dialog :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }


.example-handoff-dialog[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.example-handoff-dialog[data-dcl-scheme="dark"] a { color: #8fe1da; }
.example-handoff-dialog[data-dcl-scheme="dark"] button, .example-handoff-dialog[data-dcl-scheme="dark"] summary, .example-handoff-dialog[data-dcl-scheme="dark"] input, .example-handoff-dialog[data-dcl-scheme="dark"] select {
  color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.example-handoff-dialog[data-dcl-scheme="dark"] button:hover, .example-handoff-dialog[data-dcl-scheme="dark"] summary:hover, .example-handoff-dialog[data-dcl-scheme="dark"] button[aria-selected="true"] {
  color: #11292f; background-color: #8fe1da;
}
.example-handoff-dialog[data-dcl-scheme="dark"] dialog { color: #eff8f9; background-color: #142f36; }
.example-handoff-dialog[data-dcl-scheme="dark"] [data-note] { color: #eff8f9; background-color: #1c3c44; }
.example-handoff-dialog[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }

.example-handoff-dialog, .example-handoff-dialog * { box-sizing: border-box; }
.example-handoff-dialog { font: 1rem/1.5 system-ui, sans-serif; padding: 1rem; border-radius: 0.75rem; overflow-wrap: anywhere; }
.example-handoff-dialog h2, .example-handoff-dialog h3 { line-height: 1.15; margin-block: 0 0.75rem; }
.example-handoff-dialog p { margin-block: 0.5rem; }
.example-handoff-dialog ul { margin-block: 0.5rem; padding-inline-start: 1.5rem; }
.example-handoff-dialog article, .example-handoff-dialog details, .example-handoff-dialog [data-note] { border: 1px solid; border-radius: 0.375rem; padding: 0.75rem; }
.example-handoff-dialog button, .example-handoff-dialog summary, .example-handoff-dialog input, .example-handoff-dialog select {
  min-block-size: 44px; border: 1px solid; border-radius: 0.375rem; padding: 0.5rem 0.75rem; font: inherit;
}
.example-handoff-dialog button, .example-handoff-dialog summary { cursor: pointer; transition: background-color 140ms ease-out; }
.example-handoff-dialog button:disabled { cursor: not-allowed; text-decoration: line-through; }
.example-handoff-dialog input { display: block; inline-size: 100%; }
.example-handoff-dialog dialog { max-inline-size: min(32rem, 90vw); border-radius: 0.75rem; padding: 1rem; }
.example-handoff-dialog th, .example-handoff-dialog td { padding: 0.5rem; text-align: start; border-block-end: 1px solid; }
.example-handoff-dialog table { border-collapse: collapse; inline-size: 100%; }
.example-handoff-dialog caption { font-weight: bold; text-align: start; }
.example-handoff-dialog dt { font-weight: 600; }
.example-handoff-dialog dd { margin: 0 0 0.75rem; }
.example-handoff-dialog [hidden] { display: none !important; }
.example-handoff-dialog .parts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 1rem; }
.example-handoff-dialog .dialog-parts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); gap: 1rem; }
@media (max-width: 30rem) {
  .example-handoff-dialog[data-dcl-layout="rail"] .parts { grid-template-columns: minmax(0, 1fr); }
  .example-handoff-dialog[data-dcl-layout="rail"] .parts > :is(p, ul, article) { grid-column: 1; grid-row: auto; }
  .example-handoff-dialog[data-dcl-layout="rail"] .parts > :is(details, nav) { grid-row: auto; }
}
@media (prefers-reduced-motion: reduce) { .example-handoff-dialog * { transition: none !important; } }
</style>

When to use

Use this split arrangement when readers benefit from seeing items side by side.

Avoid

Avoid interrupting readers for updates that do not require immediate action.

Accessibility

Native dialog keeps keyboard focus inside; Escape closes it and focus returns to its opener.

Was this useful? Send feedback.