Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 2.6 — Built-in Interactive Elements
HTML · Example 2 of 3

A modal dialog with a dialog form

The script opens and closes it once to show the API. Click Delete file to open it yourself: try Escape, Cancel and Delete.

details/summary give you an open-and-close section, dialog gives you a real popup window, and the popover attribute makes menus and tips that appear on top; all with keyboard support and accessibility built in, often with no JavaScript.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Build a two-question FAQ where only one answer can be open at a time and the first is open at the start.

02

Build a "Subscribe?" modal with Yes/No buttons that logs the choice when it closes. Open it from a button.

03

Make a button that toggles a small help popover with the text "Passwords need 12 characters".

Explain it without notes

01

What does showModal() give you that show() doesn't?

02

How does <form method="dialog"> work?

03

What is light dismiss, and which kind of popover has it?

04

Why are native details, dialog and popover better than hand-built div widgets?

A modal dialog with a dialog form

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

open: true | modal: true
open after close: false
Closed with: cancel