DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • Semantic HTML
  • Accessibility (a11y)
  • Forms & Validation
  • Document Metadata & The <head>
  • The Document Object Model (DOM)
  • Character Encoding & Entities
  • Data Attributes & Custom Data
  • Template, Slot & Web Components
  • Responsive Images: Picture, Source & srcset
  • Loading Strategies & Resource Hints
  • The Native Dialog Element
  • Audio, Video & Media APIs
  • SVG Integration & Canvas Basics
  • Advanced Input Types & Datalist
  • Details, Summary, Progress & Meter
  • Global Attributes & Iframe Security
  • Microdata, Schema.org & Structured Data
  • Open Graph & Social Meta Tags
  • Security Headers & CSP in HTML
  • Link Relations & Canonical Tags
← From Beginner to Expert in Fundamentals of Frontend

The Native Dialog Element

12 min read
dialogshowModalshowclosebackdropfocus trappingreturnValue

The <dialog> Element: Native Modals

Before the <dialog> element, modals required hundreds of lines of JavaScript for focus management, keyboard handling, and backdrop clicks. Now the browser handles all of it.

Two Modes

  • dialog.show(): Non-modal. Page remains interactive behind it.
  • dialog.showModal(): Modal. Adds backdrop, traps focus, closes with Escape, blocks interaction with the rest of the page.

Built-in Accessibility

  • Automatic role="dialog"
  • Focus trapped inside the modal
  • Escape key closes it
  • Focus returns to the trigger element on close
  • ::backdrop pseudo-element for the overlay

returnValue

Buttons inside a <form method="dialog"> close the dialog and set dialog.returnValue to the button's value — useful for confirm/cancel flows.

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.