Dialog vs Modal: Semantic Differences
What you'll learn: You'll understand the key distinction between dialog elements and when to make them modal or non-modal.
What is a Dialog?
A dialog is a conversation window that opens on top of your main content. Think of it like someone tapping you on the shoulder to ask a question while you're working. The HTML <dialog> element represents this pattern semantically.
Modal vs Non-Modal: The Critical Difference
Here's where things get specific:
Modal Dialogs
A modal dialog is like a bouncer blocking the door—you must deal with it before continuing. When a modal opens:
- It traps keyboard focus (you learned focus trapping earlier)
- The rest of the page becomes inert (can't interact with background)
- Usually has a backdrop overlay
- Common for critical decisions: "Are you sure you want to delete?"
Non-Modal Dialogs
A non-modal dialog is more like a sticky note—helpful information available when needed, but you can ignore it and keep working. When non-modal:
- You can interact with the page behind it
- Focus isn't strictly trapped
- Often used for tooltips, chat windows, or inspector panels
Why This Matters for Accessibility
Screen reader users and keyboard navigators need to know whether they're "stuck" dealing with a dialog or free to move around. The semantic difference tells assistive technology how to handle focus management and announce the interaction mode.
When you use <dialog> with .showModal(), browsers automatically handle the modal behavior. With .show(), you get non-modal behavior—but you're responsible for proper focus management.
Key Takeaway: Modal dialogs demand immediate attention and block interaction with other content; non-modal dialogs allow continued interaction with the page. Choose based on how urgent and blocking your message needs to be.