Skip to content
All terms
Components/lexicon/modal

What is a Modal Dialog?

also known asdialog · popup · overlay · lightbox

A modal dialog is an overlay that sits above the page, blocks interaction with everything behind it, and asks for a decision or a short input.

Made ofA dialog over a dimmed backdrop, with focus kept inside it and Escape to close.

Key CSSdialog::backdrop { background: rgb(0 0 0 / 0.5) }position: fixed; inset: 0overscroll-behavior: contain
Delete project?
×
This permanently deletes Orbit and its 14 files. You cannot undo it.
Cancel
Delete
01 · Definition

You are halfway through editing a document and click the close button. Everything behind goes dim, a small card appears and asks whether you want to save your changes. You cannot click anything else until you answer. That interruption, on purpose, is a modal dialog. The word 'modal' means the interface has entered a mode: the dialog owns your attention until you finish with it or dismiss it.

That power is exactly why modals deserve restraint. They break the flow, so they should appear only when the user must acknowledge something or give a small, focused piece of input. Good reasons include destructive confirmations such as deleting a project, quick forms that do not justify a full page such as inviting a teammate, and critical information that cannot be missed. Poor reasons include marketing offers, newsletter pop-ups, onboarding tours and anything the user could safely ignore. For lightweight feedback, a toast is gentler. For long forms, a dedicated page is better.

The modern layout is calm and predictable. A centred card, often around 520 pixels wide at most, sits over a dimmed or softly blurred backdrop. It has a clear title, optional supporting text, and one or two buttons aligned to the right. The button that confirms the action takes the strongest style, using a red tone for destructive actions and the brand colour for constructive ones. A close icon sits in the top corner, and the Escape key always dismisses the dialog. Button labels should name the action, such as 'Delete project' and 'Keep project', instead of a vague 'OK' and 'Cancel'.

The hardest part is behaviour, not looks. A well-built modal moves keyboard focus inside when it opens, keeps focus trapped there so Tab does not wander into the hidden page, and returns focus to the element that opened it when it closes. It tells assistive technology that it is a dialog with a label. It prevents the background from scrolling. Getting all of that right by hand is fiddly, which is why many modals are accessibility problems in practice.

The native HTML dialog element helps a great deal. Opened with showModal(), it gives you a top-layer overlay, a styleable ::backdrop, Escape handling and focus management out of the box, and the browsers support it widely. Headless libraries such as Radix or React Aria are good choices when you need extra polish or finer control over animation and edge cases.

A few rules save you from trouble. Never open one modal on top of another, because users lose track of where they are. Do not auto-open a modal on page load, except for something genuinely required like a legal acknowledgment. Be careful with click-outside dismissal for forms, where one stray click could throw away someone's input. Keep the content short, and if you find yourself adding scroll bars, tabs or multi-step flows, move it to a page or a side panel.

On small screens, many teams switch the pattern to a bottom sheet that slides up from the edge, which is easier to reach with a thumb.

When prompting an AI, spell out the behaviour: use the native dialog element, a 480px card, a destructive red primary button, Escape to close, focus returned to the trigger, and no click-outside close for the form version.

Use when
  • Destructive confirmations (delete, archive, leave unsaved)
  • Quick forms that don't justify a full page (invite user, edit profile)
  • Critical information requiring acknowledgment
Avoid when
  • Non-critical confirmations, use a toast
  • Long forms, use a dedicated page
  • Onboarding tours, use coachmarks or a side panel
02 · Do
  • +Trap focus inside the modal until it closes
  • +Bind `Esc` to close and click-outside to dismiss (for non-destructive modals)
  • +Use `<dialog>` element or proper ARIA roles
  • +Color the primary button by intent (red = destructive, brand = constructive)
03 · Don't
  • −Don't stack modals, never open one modal on top of another
  • −Don't use modals for marketing, they're hated
  • −Don't auto-open modals on page load except for critical legal acknowledgments
06 · Common questions

Modal Dialog: your questions, answered

What is a modal dialog?

It is an overlay that appears over the page, usually dimming the background, and blocks interaction with everything else until the user responds or dismisses it. It is used for confirmations, short forms and critical messages.

Should I use the native HTML dialog element?

Yes when you can. Opened with showModal(), it provides focus handling, Escape support and a styleable backdrop for free, and browser support is strong. Headless libraries like Radix or React Aria are good fallbacks for extra polish.

When should I avoid a modal?

Avoid it for non-critical messages, long forms, onboarding tours and marketing offers. A toast suits light feedback, a full page suits long tasks, and an inline element suits optional help. Interrupting people should be rare.

How do I make a modal accessible?

Move focus into the dialog on open, trap it there, close with Escape, and return focus to the trigger afterwards. Give the dialog an accessible name, prevent background scrolling, and write button labels that describe their actions.

Should a modal close when I click outside?

For simple, non-destructive dialogs, yes, it feels natural. For forms or destructive confirmations, be careful, because an accidental click can discard someone's input. Offer an explicit close or cancel button in every case, and keep Escape working.

People also ask

More quick answers

Modal vs toast: what's the difference?

A modal blocks the page and demands a response, while a toast appears briefly and lets people carry on. Use toasts for confirmations and modals only for decisions.

Modal vs popover or tooltip?

Popovers and tooltips are non-blocking and attach to an element. A modal covers the page and takes focus, so it should be reserved for important moments.

Are modals bad for UX?

Not inherently. They are bad when overused or used for marketing. For destructive confirmations and short focused tasks they remain one of the clearest patterns.

What is a bottom sheet?

It is the mobile cousin of a modal, sliding up from the bottom edge so it is easy to reach with a thumb. Many products swap modals for sheets on small screens.

Can a command palette be a modal?

It is built like one, with a dialog, focus trapping and Escape, but it is summoned by the user, not by the app. That difference makes it feel helpful instead of interrupting.

07 · Related terms
Free and open source

Found this useful? A GitHub star helps other designers find it.

Star on GitHub