Open code, practice, and notes →
Download source with English comments · for reading
HTML · 17 dialog and Modal Flow
Series contents · Technology map
Stage: Native UI and Media · Editable example · Storage ID: html-step-17
Goals and learning outcomes
- Check keyboard operation inside the modal and closing with Escape.
- Record whether focus returns to the open button after closing.
Prerequisites
The work and experiment records from Unit 16, “A Collapsible Table of Contents with details”.
Key concepts and explanations
Modal Behavior
showModal displays a dialog in the top layer and restricts outside interaction. Its modal behavior differs from setting only the open attribute.
Returning Focus
Users must be able to return to their original task after closing a dialog. Check initial focus and Escape behavior in an actual browser.
Practice setup
First check the execution scope guidance on the example screen. The following environment is for extending the assignment in a separate project. Implement it yourself in a separate local project and check it with browser developer tools. Prepare HTML and any necessary image/media files in a separate folder and open them through a local HTTP server. Check with the Elements and accessibility panels and actual keyboard operation.
The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.
Practice tasks
- In dialog.html, prepare opening and closing with the keyboard, and Escape.
- Create a titled dialog and open/close buttons, and connect showModal and close with supporting JS.
- Run with opening and closing with the keyboard, and Escape. Results to check: Check keyboard operation inside the modal and closing with Escape. Record whether focus returns to the open button after closing. Record expected and actual results separately.
Variables to observe
| Variable | Baseline | Change | Expected change / hypothesis |
|---|---|---|---|
| Opening Method | showModal | open attribute | Pre-run hypothesis: Restrictions on outside interaction will differ. Keep other conditions fixed and record the actual result separately after running. |
Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.
Completion criteria
- Check keyboard operation inside the modal and closing with Escape.
- Record whether focus returns to the open button after closing.
Self-check
- How do you associate a dialog with its title?
- Where is an appropriate place for initial focus inside a modal?
Official references
Linked example and execution scope
Example source · Runtime environments and limits
Dedicated helper code connects the open button to showModal. Compare the dialog open attribute with modal focus behavior. Scope document body/html selectors within Shadow DOM. @media responds to the outer preview viewport, while the width slider changes only the container. Network access, form navigation, and iframe execution are restricted.
Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.
Next learning
Previous: A Collapsible Table of Contents with details · Next: Media Captions and Alternatives