show() vs showModal() Methods
You'll learn: How to display a <dialog> element using two different methods that behave very differently in terms of user interaction and accessibility.
When you're ready to display a <dialog> element, you have two JavaScript methods available: show() and showModal(). The choice between them fundamentally changes how users interact with your dialog.
The show() Method
Calling show() on a dialog element makes it appear on the page as a non-modal dialog. This means:
- The dialog appears, but users can still interact with content behind it
- Focus can move freely between the dialog and the rest of the page
- There's no backdrop overlay blocking the page
- The page remains scrollable
- No focus trap is created
Think of it like opening a side panel or notification that sits on top of the page—users aren't forced to deal with it immediately.
The showModal() Method
Calling showModal() creates a modal dialog that demands attention:
- The rest of the page becomes inert (cannot be interacted with)
- A backdrop overlay typically appears behind the dialog
- Focus is trapped inside the dialog
- The Escape key closes the dialog by default
- Users must interact with the dialog before accessing other content
This is like a traditional popup—the user must respond before continuing.
Which Should You Use?
Use showModal() for critical interactions that require immediate attention (confirmations, required forms). Use show() for informational dialogs or non-blocking content that users can address later.
Key Takeaway: show() displays a non-modal dialog that allows page interaction, while showModal() creates a modal dialog that blocks all other page interaction until dismissed.