Patch Bandit

The story / The lab

Donut hole · 2026-11-22

HTML dialog modal with zero JavaScript

An HTML dialog element gives you a real accessible modal—top-layer stacking, an inert background, a blurred backdrop, and Escape to close—straight from the browser. Pair it with declarative invoker commands (commandfor) and @starting-style, and the whole HTML modal opens, animates from display: none, and closes with zero lines of JavaScript.

Delete the modal library and let the browser handle the trap.

Snick the raccoon opening a native HTML modal dialog

Try the zero-script modal

Press the launch button to open a real <dialog> modal driven solely by commandfor and command="show-modal". Notice how the page behind blurs out, keyboard focus moves straight inside, and Esc returns focus to the button you clicked.

Use the optional closedby="any" switch in the launchpad if you also want clicks on the dimmed backdrop to close the modal.

  • Zero JavaScript: no showModal() boilerplate and no click-outside listener.
  • Smooth display: none fade: CSS @starting-style handles both entry and exit.
  • Reduced motion safe: visitors who prefer reduced motion get an instant, steady open and close.

Interactive modal launchpad

Choose backdrop behavior, then launch

Optional: closedby="any" light dismiss

<dialog id="stash-modal"><dialog id="stash-modal" closedby="any">

Optional attribute note: closedby="any" is supported in Chrome 134+, Edge 134+, and Firefox 141+, and is not yet in Safari (Safari ignores the attribute while keeping Esc and the close button working normally).

Zero JavaScript · default modal

Native HTML dialog in the top layer

Opened with commandfor="demo-dlg-strict" and command="show-modal", then faded in from display: none with CSS @starting-style.

The page behind this box is inert right now. Press Esc or use the close button below to dismiss it and return focus cleanly.

Zero JavaScript · closedby="any"

Backdrop light-dismiss modal

This <dialog> adds closedby="any", so clicking the blurred backdrop outside this box closes it alongside Esc and the close button.

In Safari (where closedby is not yet supported), the browser safely ignores that attribute and keeps Esc and the button below working.

Four native pieces behind a CSS modal

Putting these four standard features together replaces focus-trap scripts, z-index battles, and transition state timers.

  • 01

    The HTML dialog element

    When opened as a modal, <dialog> jumps into the browser's top layer above sticky headers, marks the rest of the page inert, and renders a styleable ::backdrop.

  • 02

    Declarative invoker commands

    Putting commandfor="id" and command="show-modal" or command="close" right on a <button> replaces addEventListener and showModal() scripts.

  • 03

    Animate display: none with @starting-style

    Because closed dialogs are display: none, CSS @starting-style sets the opening frame while allow-discrete transitions overlay and display cleanly on close.

  • 04

    Optional closedby="any"

    Want clicking the dimmed backdrop to close the modal too? One HTML attribute adds light dismiss in supporting browsers without wiring a backdrop click handler.

Copy the HTML dialog and CSS starting-style code

Zero-JS modal markup (HTML)
<!-- Open and close a real modal with zero JavaScript -->
<button type="button" commandfor="stash-modal"
  command="show-modal">Open modal</button>

<!-- Optional: add closedby="any" for backdrop click dismiss -->
<dialog id="stash-modal" closedby="any"
  aria-labelledby="modal-h">
  <h2 id="modal-h">Native HTML dialog</h2>
  <p>Escape closes it, the page behind is inert,
     and focus returns on close.</p>
  <button type="button" commandfor="stash-modal"
    command="close">Close modal</button>
</dialog>

Modal surface and ::backdrop (CSS)
dialog {
  margin: auto;
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.5rem 1.6rem;
  border: 2px solid #86e3be;
  border-radius: 18px;
  background: #1e1033;
  color: #fff2de;
  box-shadow: 0 28px 70px rgb(0 0 0 / 0.72);
}

dialog::backdrop {
  background: rgb(14 6 25 / 0.76);
  backdrop-filter: blur(5px);
}

Smooth open and close with @starting-style (CSS)
/* Animate dialog in and out from display: none (zero JavaScript) */
@media (prefers-reduced-motion: no-preference) {
  dialog {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
    transition:
      opacity 0.24s ease,
      transform 0.24s ease,
      overlay 0.24s allow-discrete,
      display 0.24s allow-discrete;
  }

  dialog[open] {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  @starting-style {
    dialog[open] {
      opacity: 0;
      transform: translateY(14px) scale(0.96);
    }
  }

  dialog::backdrop {
    opacity: 0;
    transition:
      opacity 0.24s ease,
      overlay 0.24s allow-discrete,
      display 0.24s allow-discrete;
  }

  dialog[open]::backdrop { opacity: 1; }

  @starting-style {
    dialog[open]::backdrop { opacity: 0; }
  }
}

Browser support (checked 2026-11-22): The <dialog> element is Baseline Widely Available across Chrome 37+, Edge 79+, Firefox 98+, and Safari 15.4+ (Web Platform Dashboard: dialog). Invoker commands (commandfor / command) are Baseline Newly Available since December 2025 across Chrome 135+, Edge 135+, Firefox 144+, and Safari 26.2+ (Web Platform Dashboard: invoker-commands). @starting-style is Baseline Newly Available across Chrome 117+, Edge 117+, Safari 17.5+, and Firefox 129+ (Web Platform Dashboard: starting-style). Optional closedby="any" is Chrome 134+, Edge 134+, and Firefox 141+, not yet in Safari (Web Platform Dashboard: dialog-closedby). Tested in Chromium only.

The fine print, in plain words

Why this is free

We're raccoons who think simple things shouldn't cost a monthly fee. We take techniques apart, explain them in plain words, and give them away. The code on this page is MIT licensed: copy it, change it, and share it.

This is one of twelve experiments so far. Our first browser tool (Bandit Codes) is live now, and the rest sit as ideas in the stash.