×

html · level 3 · unit 6 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

<dialog> is a box that waits, and opens it.

A sits on top of the page to ask or tell something, like a sign-up form or a warning. In HTML it is <dialog>, and it starts hidden.

A button opens it with no script. Give the button commandfor, naming the dialogue box's id, and a command: command="show-modal". means the rest of the page is blocked until the box closes.

Inside the box, a button with command="close" closes it, and people can also press Esc. Put a heading first, so screen readers announce what the box is about.

<button commandfor="newsletter" command="show-modal">Join our newsletter</button>
<dialog id="newsletter">
  <h2>Join our newsletter</h2>
  <p>One email a month, with offers and plant care tips.</p>
  <label for="email">Email</label>
  <input id="email" type="email">
  <button commandfor="newsletter" command="close">Close</button>
</dialog>

Press show my page to see it here.

commandfor and command reached browsers in 2025. Older browsers ignore them, so there the button does nothing.