Skip to main content
ContainersLevel 1

Modal

模态框 / 对话框

WebMobileDesktopDifficulty: Medium

Something pops up in the middle of the screen, and until you deal with it you cannot use the page underneath.

01

Live Demo

Actually clickable
Hit "Delete photos" and the dialog stops you. Try Tab (focus is trapped inside) and Esc (to close).

What you just saw:The small dialog that appears after you tap "Delete photo", the composer that expands from the center of the screen while you write a comment, the centered form panel on a sign-in or sign-up page.

02

What it actually is

A modal intercepts the user: the page behind it dims, stops responding to clicks, and stops scrolling. It has exactly two legitimate uses — a decision that must be made right now, or a focused input environment. Almost everything else can be solved with a non-blocking alternative.

modaldialogmodal dialogpopup windowoverlay dialogblocking dialog
03

Anatomy · What it's made of

  1. Scrim遮罩

    Translucent black, usually dismisses on click

  2. Dialog Surface对话框

    White background, border-radius 12px, max-width 480px

  3. Title标题

    State the consequence, not "Notice"

  4. Body内容

    No more than 3 lines

  5. Actions操作区

    Right-aligned: cancel + confirm

  6. Close关闭

    ✕ in the top-right corner, or press Esc

04

When to Use

When it fits, and when it doesn't
Modal usage recommendations
SituationUse it?
A decision is required before anything else can proceed (confirmation)Yes
The user needs a focused input environment (sign-in, comment)Yes
A serious error needs to interrupt the userYes
You only want to display a piece of informationNo
It has to carry a multi-step task (a long form)No

Popping up a dialog on every button press is the most common experience disaster there is.

A modal inside a modal is a design incident — use breadcrumbs or a stepper instead.

05

Similar Patterns

Don't mix these up
Full comparisonDialog vs Bottom Sheet vs DrawerI need to bring up a layer on top of the current screen. Which one?See the table
06

How to tell AI

Three levels of prompt

Add the component name and specifics

After tapping "Delete", show a confirmation dialog: the title states the consequence, the body is no more than two lines, and the bottom right-aligns "Cancel" and a red "Delete" button. Both Esc and a scrim click dismiss it.

07

Don't just say this to AI

Bad → Better

Don't say this to AI

Make a dialog pop up when the user clicks.

Say this instead

Show a confirmation dialog (role=dialog aria-modal): the title states the consequence instead of saying "Notice", the body is ≤2 lines, and the bottom right-aligns "Cancel + red Delete". Esc and scrim click both close it; focus is trapped on open and body scroll is locked.

08

Share this card

Social-ready

Turn this pattern into a 3:4 or 1:1 knowledge card and export it as PNG right in the browser. No backend needed.