Delivery details and other short messages can be available on demand without taking up space on the page. HTML button commands let visitors open and close a modal dialog without JavaScript.

A modal dialog blocks interaction with the rest of the page while it is open. A heading names the dialog for assistive technology, and a visible Close button gives visitors a way back to the page.

The button attributes command and commandfor are supported in Chrome 135, Firefox 144, and Safari 26.2 or later. Older browsers can display the buttons even if they ignore the commands.

Steps to open and close an HTML dialog without JavaScript:

  1. Start a new file named dialog.html in your text editor.
  2. Write the page markup with the Show delivery details button in dialog.html.
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Delivery information</title>
      <style>
        body { margin: 2rem; font: 1.25rem system-ui, sans-serif; }
        button { font: inherit; }
        button:focus { outline: 3px solid #174ea6; outline-offset: 4px; }
      </style>
    </head>
    <body>
      <h1>Delivery information</h1>
      <button type="button" command="show-modal" commandfor="delivery-dialog">
        Show delivery details
      </button>
    </body>
    </html>

    The show-modal command opens the dialog with the ID named in commandfor. The style gives the focused button a blue outline.

  3. Insert the <dialog> markup immediately after the Show delivery details button inside <body>.
      <dialog id="delivery-dialog" aria-labelledby="delivery-title">
        <h2 id="delivery-title">Delivery details</h2>
        <p>Orders ship in two business days.</p>
        <button type="button" command="close" commandfor="delivery-dialog" autofocus>
          Close
        </button>
      </dialog>

    Both buttons target delivery-dialog, and the close command dismisses it. The aria-labelledby attribute points to the dialog heading, and autofocus puts keyboard focus on Close when the dialog opens. The dialog starts closed because it has no open attribute.

  4. Save dialog.html.
  5. Open the saved dialog.html file in desktop Chrome.

    In the address bar, a local file URL starts with file:/// and contains the path where you saved the file.

  6. Press Tab to focus Show delivery details.
  7. Press Enter on Show delivery details to open the dialog.

    Delivery details appears over the dimmed page, with a blue outline around Close.

  8. Click Close inside the dialog.
  9. Press Enter again to reopen Delivery details.

    After the dialog closes, the blue outline returns to Show delivery details.

  10. Press Escape to dismiss Delivery details.
  11. Verify that focus returns to Show delivery details.

    The dialog and its backdrop disappear, and a blue outline surrounds Show delivery details again.

Share this guide