Modal dialog

Also known as: modal

On this page 7

A modal dialog is an interface window that appears above the current screen and blocks interaction with everything underneath until the user completes, confirms or dismisses it. In UI design, a modal, as it is usually called, is the strongest way to demand attention short of navigating away, which makes it valuable for decisions that cannot be skipped and disruptive when used for anything less.

The defining property is modality, not appearance. A centered card with a dimmed backdrop that still lets users click the page behind it is a non-modal dialog, while a full-screen sheet that locks the rest of the interface is modal even without a visible overlay.

How a modal dialog takes control of the interface

A modal dialog works by creating a temporary interaction mode: input is captured by the dialog, and the rest of the application becomes inert. Visually this is signaled with a scrim or backdrop, a semi-transparent layer that dims the page, typically at 30 to 60 percent opacity, so the dialog reads as the only active surface.

Correct behavior goes beyond visuals. A well-built modal moves keyboard focus into the dialog when it opens, traps focus so that Tab cycles only through its controls, closes on the Escape key when dismissal is safe and returns focus to the triggering element when it closes. Screen readers must also be prevented from reading the content behind it.

PartPurposeDesign guidance
BackdropSignals that the page is inactiveDim, do not hide context entirely
TitleStates the question or taskShort, specific, used as the accessible name
BodyExplains consequences or holds the formKeep to what the decision needs
Primary actionCompletes the taskVerb label such as Delete project
Secondary actionCancels or goes backVisually weaker, always present
Close controlDismisses without actionOmit only for mandatory decisions
Anatomy of a modal dialog

Types of modal dialogs

Modal dialogs fall into a few functional types, and each has different rules for dismissal, size and content. Treating them as one pattern leads to confirmation boxes that are too easy to dismiss and forms that are too cramped.

TypeTypical contentDismissible by backdrop clickTypical width
Alert dialogCritical message needing acknowledgmentNo320 to 480 px
Confirmation dialogDestructive or irreversible actionNo400 to 560 px
Form dialogShort task with a few fieldsOnly if no data is lost480 to 720 px
LightboxEnlarged image or mediaYesUp to full viewport
Full-screen modalComplex task on small screensNo, uses explicit close100 percent of viewport
Common modal types and their behavior

On mobile devices, modals often take the form of a bottom sheet or full-screen view, because a small centered card leaves too little room for touch targets and on-screen keyboards. The modality principle stays the same even when the shape changes.

The right choice depends on how urgent the information is and whether the user must act. Many overlays that look similar differ precisely in whether they block the interface.

PatternBlocks the pageRequires a responseBest for
Modal dialogYesYesIrreversible decisions, short focused tasks
Non-modal dialogNoNoTools that work alongside the page
Toast notificationNoNoBrief status feedback that disappears
Drawer or side panelSometimesNoDetail views and longer editing
Inline messageNoSometimesErrors and hints tied to one field
PopoverNoNoSmall contextual options near a trigger
Modal dialog and neighboring patterns

A useful test is to ask what happens if the user ignores the content. If ignoring it is harmless, a non-blocking pattern is better. If ignoring it could cause data loss or an unintended action, a modal is justified.

When to use a modal and how to design it

Use a modal dialog when the user must make a decision before continuing or when a short task benefits from isolation, such as renaming a file or entering a payment code. Avoid it for content people want to compare with the page, for long multi-step processes and for marketing interruptions.

  • Write action-specific labels: Delete 3 files and Keep files are clearer than OK and Cancel.
  • State consequences in the body: say what will be lost and whether it can be undone.
  • Place the destructive action deliberately and never make it the default focus.
  • Keep content short so that no internal scrolling is needed on common screen sizes.
  • Never stack modals; a modal opening another modal signals a flow that needs its own page.

For implementation, the native HTML dialog element opened with showModal() provides built-in inertness, Escape handling and a top layer. Custom implementations should follow the WAI-ARIA dialog pattern, using role="dialog" or role="alertdialog" together with aria-modal="true" and a label that points to the title.

Common mistakes and their effects

Most modal problems come from overuse and incomplete accessibility. Each unnecessary interruption trains users to dismiss dialogs without reading them, which weakens the modals that matter.

  • Interrupting on page load with newsletter or cookie prompts pushes users away before they see content.
  • Missing focus management leaves keyboard and screen reader users stranded behind the overlay.
  • Losing form data when a dialog closes by an accidental backdrop click.
  • Background scrolling that continues while the modal is open, which disorients touch users.

The short version

A modal dialog is a small window that pops up over a page and makes you deal with it first. Until you answer it or close it, the rest of the screen is paused and darkened.

It is like a shop assistant who steps in front of you before you leave and asks whether you really want to cancel your order. That is helpful when the question matters and annoying when it does not. The main idea is that a modal should appear only for things that truly need your attention right now.

Where it makes a difference

In a project management tool, a user selects a project with 240 tasks and chooses Delete. Earlier versions of the product deleted it immediately, and support received frequent requests to recover lost work.

The team adds a confirmation modal titled Delete Website redesign, with a body explaining that all 240 tasks and their comments will be removed permanently. The primary button reads Delete project and is styled in red, the secondary button reads Keep project and receives initial keyboard focus, and clicking the backdrop does nothing. After release, accidental deletions drop sharply, while users who intend to delete a project need only one extra click. The modal adds friction exactly where an irreversible action justifies it.