Skip to content
SkillCodex
Menu

Modal dialog

Modal dialog

A focused surface for a contained task that makes the rest of the page temporarily inactive.

Try the component
Context, sources and actions
Sources and revision
Updated
Version
v1.0.26 · r2
Sources
5 sources
Status
Published
Read the sources

You may have searched for: a window over the page for editing detailsopen a form and block the backgrounda centered box I must finish or close

All phrasings

Decisive difference Alert dialog interrupts for one decision to confirm or cancel; Modal dialog hosts a broader contained task such as a form. Compared with Alert dialog

Save and share

Recognize

Modal surfaces

Try it

Is the task about acting, confirming a consequential decision, or viewing media?

Modal dialog

Shared trial context

A project item opens a focused overlay while the underlying workspace remains unavailable until the user finishes or closes it.

Modal dialog

Mission

Modal dialog

Open the dialog, tab through every control, cancel with Escape, and verify focus returns to Edit member.

Live result

The dialog is closed. The page remains available.

Step 1 of 3

Try

Try the component. Your live result appears just above. Move on at your own pace.

Behavior and edge case
What to observe
The edit form opens with its title announced and focus on the first useful field.
Edge case
A validation error keeps the dialog open, links the message to the invalid field, and moves focus only when submission fails.
What this example shows

Use a Modal dialog for a general contained task; use Alert dialog for a short consequential decision and Lightbox when viewing media is the task.

Which fits your need?

Modal dialog

Editing a compact record without losing page context

Alert dialog

Confirming a permanent deletion

Which component will you use here?
Difference and sources

Use a Modal dialog for a general contained task; use Alert dialog for a short consequential decision and Lightbox when viewing media is the task.

Read the sources
    Parts of the specimen

    Select a numbered marker on the schematic, or use the list below, to see its role. The schematic shows the concept's representative state.

    Backdrop

    The layer that separates a modal surface from inactive page content.

    Level 1

    Understand

    In your own words

    What people describe

    Documented aliases: modal, dialog, modal window

    • a window over the page for editing details
    • open a form and block the background
    • a centered box I must finish or close
    • show settings without leaving this page
    • a popup that traps focus until closed
    • a window that blocks the whole screen

    Position in the atlas

    Relationship map

    Locate the chapter, neighboring concepts, and the next useful decision.

    • Chapter

      Modal surfaces

      Modal dialog belongs to this comparison group.

    • Do not confuse

      Alert dialog

      Choose Modal dialog if the task needs several fields or steps while the page stays in the background. Choose Alert dialog if the user must confirm or cancel a consequential action, with no other input.

      Compare this pair
    • Do not confuse

      Lightbox

      Choose Modal dialog if the user fills in a form or completes another contained task. Choose Lightbox if viewing or browsing images or videos is the primary task.

      Compare this pair
    • Next step

      Compare the concepts in the chapter before choosing an implementation.

      Open the chapter

    Level 2

    Apply

    Choose

    Use it when

    • Editing a compact record without losing page context
    • Completing a short focused form

    Avoid it when

    • The workflow is long enough to deserve its own page
    • The information can remain nonmodal and contextual

    Compare

    Compare similar concepts

    Platform equivalents

    The same interaction can have a different name or contract on each platform. Check the mapping before choosing an API.

    • HTML

      Direct

      <dialog>.showModal()

      HTML Living Standard 2026-09

      showModal() makes the document outside the dialog inert; focus and labeling still need explicit content.

      Verified Official documentation
    • WAI-ARIA APG

      Direct

      role="dialog" + aria-modal="true"

      WAI-ARIA APG 2026-09

      The pattern defines contained focus, Escape dismissal, return focus, naming, and modal semantics.

      Verified Official documentation
    • Radix UI

      Direct

      Dialog.Root

      @radix-ui/react-dialog 1.1.x

      Modal is the default and the primitive manages focus, Escape, outside interaction, and return focus.

      Verified Official documentation
    • shadcn/ui

      Direct

      Dialog

      shadcn/ui docs 2026-09-03

      The Dialog recipe exposes the Radix dialog contract with authored content and styling.

      Verified Official documentation
    • Material UI

      Direct

      Dialog

      Material UI v9.4.0

      Dialog provides a modal surface; title, description, actions, and initial focus remain application decisions.

      Verified Official documentation
    • SwiftUI

      Partial

      .sheet

      SwiftUI documentation 2026-09

      A sheet is a modal presentation, but its size and interaction model adapt by Apple platform and device.

      Verified Official documentation
    • Jetpack Compose

      Direct

      Dialog

      Android Developers 2026-08

      Dialog opens a modal window; the application supplies the container, content, dismissal, and actions.

      Verified Official documentation
    • Flutter

      Direct

      showDialog<T>() + Dialog

      Flutter API docs 2026-09

      showDialog adds the modal route and barrier while Dialog supplies the surface.

      Verified Official documentation

    Understand → Recognize → Choose → Compare

    Pack for your agent

    Pre-written instructions to paste into your agent. Copying executes nothing.

    Implement correctly

    Build Modal dialog without breaking its behavior

    # Implement Modal dialog in your agent
    
    ## Objective
    Implement Modal dialog for this verified behavior: A focused surface for a contained task that makes the rest of the page temporarily inactive.
    
    ## Prerequisites
    - Inspect the repository, design system, and existing tests first.
    - Preserve unrelated changes and keep the file scope bounded.
    - Confirm that Modal dialog matches the need before writing code.
    
    ## Required behavior
    - While modal, keyboard focus stays inside the surface until it closes.
    - Escape closes the temporary surface and returns focus to a sensible control.
    
    ## States to cover
    - Dialog closed
    - Dialog open
    
    ## Accessibility
    - ARIA role: dialog[aria-modal=true]
    - The primary control or named region for Modal dialog has a stable accessible name from visible text or an explicit programmatic label; placeholder text and tooltips are not names.
    - Opening moves focus inside, Tab cannot reach the inert page, and closing restores focus to the logical opener.
    - Cancel, the named close control, and Escape close without saving; outside press is enabled only when accidental loss is harmless.
    - Assistive technology receives the dialog role, accessible title, description, and validation updates.
    - Tab and Shift+Tab cycle inside the dialog
    - Escape closes when cancellation is safe
    - Enter submits only from the intended control
    
    ## When not to use
    - The workflow is long enough to deserve its own page
    - The information can remain nonmodal and contextual
    
    ## Acceptance criteria
    - The page behind the dialog is inert
    - The dialog has an accessible title and description
    - Focus is contained and then restored
    - Every dismissal path handles unsaved work safely
    
    ## Guardrails
    - Show the proposed changes before any external action.
    - Do not publish, send, delete, pay for, or change remote state without explicit authorization.
    - Preserve unrelated changes and stop if the scope becomes ambiguous.
    
    ## Output format
    - Outcome or verdict.
    - Files or actions involved.
    - Checks run and observable evidence.
    - Remaining blockers or limitations.
    
    • @radix-ui/react-dialog
    • Requires · Access to the repository, design system, and tests
    Why it works
    • The need is tied to canonical behavior before any technical choice.
    • States, accessibility, and non-goals prevent a merely visual implementation.
    • Acceptance criteria and the output format make verification observable.

    Try next

    Verify Modal dialog on a real journey

    # Verify Modal dialog after implementation
    
    ## Objective
    Audit the Modal dialog implementation against its behavior, states, and accessibility requirements without changing it automatically.
    
    ## Checks
    - Replay the smallest representative journey.
    - Check keyboard behavior, focus, accessible name, and announcements.
    - Tie each gap to a specific acceptance criterion.
    
    ## Guardrails
    - Show the proposed changes before any external action.
    - Do not publish, send, delete, pay for, or change remote state without explicit authorization.
    - Preserve unrelated changes and stop if the scope becomes ambiguous.
    
    ## Output format
    - Outcome or verdict.
    - Files or actions involved.
    - Checks run and observable evidence.
    - Remaining blockers or limitations.
    

    sha256:f2b0f16a3c7c7bba10f0bd1323994b4a4e0b726d44f2fb628d2b1fceddcaed70

    Diagnose a problem

    Find and fix the Modal dialog defect

    # Debug Modal dialog in your agent
    
    ## Observed symptom
    [DESCRIBE THE SYMPTOM HERE]
    
    ## Observable checks
    - Reproduce the issue with the smallest relevant journey.
    - Compare behavior with the documented states and transitions for Modal dialog.
    - Verify keyboard behavior, focus, accessible name, and announcements.
    
    ## Possible causes
    - The chosen primitive does not match the expected behavior.
    - A state, transition, or focus return is missing.
    - A neighboring component captures an event or hides an accessible signal.
    
    ## Bounded corrections
    - Fix the reproduced cause without recreating neighboring components.
    - Preserve the public contract and add a focused regression test.
    - Do not install dependencies or change remote state without authorization.
    
    ## Final verification
    - The page behind the dialog is inert
    - The dialog has an accessible title and description
    - Focus is contained and then restored
    - Every dismissal path handles unsaved work safely
    
    ## Guardrails
    - Show the proposed changes before any external action.
    - Do not publish, send, delete, pay for, or change remote state without explicit authorization.
    - Preserve unrelated changes and stop if the scope becomes ambiguous.
    
    ## Output format
    - Outcome or verdict.
    - Files or actions involved.
    - Checks run and observable evidence.
    - Remaining blockers or limitations.
    
    • @radix-ui/react-dialog
    • Requires · Access to the repository, design system, and tests
    Why it works
    • The explicit symptom prevents starting from an assumed fix.
    • Checks separate behavior, accessibility, and neighboring interference.
    • The fix stays bounded and must produce regression evidence.

    Try next

    Lock in the Modal dialog fix

    # Prevent the Modal dialog regression
    
    ## Objective
    Turn the reproduced cause into a focused regression test and compare Modal dialog with neighboring concepts before widening the fix.
    
    ## Checks
    - Prove that the test fails before the fix.
    - Prove that it passes after the bounded fix.
    - Verify that no neighboring component changed behavior.
    
    ## Guardrails
    - Show the proposed changes before any external action.
    - Do not publish, send, delete, pay for, or change remote state without explicit authorization.
    - Preserve unrelated changes and stop if the scope becomes ambiguous.
    
    ## Output format
    - Outcome or verdict.
    - Files or actions involved.
    - Checks run and observable evidence.
    - Remaining blockers or limitations.
    

    sha256:2b5d7cbbc56f499708ef8d4de5db6af51d50387ccabc4e242f69fd45be3edc57

    Full entry, saving and provenance

    Pre-written instruction by SkillCodex — your request is neither sent nor used to adapt this text; no content is generated, and copying executes nothing.

    Pack digest: sha256:eb309480c7c519e6bae19817ecfc53cb5079f2c58b08b47688f8e54e5b77c360

    In code

    TechnologyPrimitiveVersionCaveat
    @radix-ui/react-dialog

    Dialog.Root

    @radix-ui/react-dialog@1.1.19Radix supplies modal focus mechanics; labeling, wording, layout, and product testing remain application work.

    Level 3

    Verify

    Impact profile

    Measured implementation costs and operating constraints for this SkillCodex specimen. A missing evaluation is never treated as free.

    Rendering
    Client
    Lazy weight
    15 kB-gzip
    Measured ·
    Environment
    macOS 26.6.2; Node 24.19.0; pnpm 10.34.5; Next.js 16.3.0 Turbopack; Chromium 140
    Method
    Sum of gzip -9 bytes for the lazy files of module 29012 in .next/server/app/(en)/term/[slug]/page/react-loadable-manifest.json after pnpm build:local at c9f1299.
    Low-end devices
    Fine
    Measured ·
    Environment
    macOS 26.6.2; Node 24.19.0; pnpm 10.34.5; Next.js 16.3.0 Turbopack; Chromium 140
    Method
    Loaded the 390 x 844 term route in isolated Chromium with 6x CPU throttling and reduced motion, then exercised the first state change; failures are recorded as non-blocking warnings.
    CPU / GPU
    React state and a Radix DOM portal drive the modal; no canvas or WebGL path is present.
    Measured ·
    Environment
    macOS 26.6.2; Node 24.19.0; pnpm 10.34.5; Next.js 16.3.0 Turbopack; Chromium 140
    Method
    Static source inspection of the target lab module plus an interaction on the isolated Chromium verification route; checked DOM/React work and absence of canvas or WebGL.
    Reduced motion
    The global reduced-motion contract collapses animation and transition durations; the same states and controls remain available.
    Measured ·
    Environment
    macOS 26.6.2; Node 24.19.0; pnpm 10.34.5; Next.js 16.3.0 Turbopack; Chromium 140
    Method
    Inspected src/app/globals.css prefers-reduced-motion rules and repeated the target interaction with reducedMotion=reduce in Chromium.
    Static fallback
    Without JavaScript, the term route stays on its localized Loading fallback; the profile and initial specimen are not revealed.
    Measured ·
    Environment
    macOS 26.6.2; Node 24.19.0; pnpm 10.34.5; Next.js 16.3.0 Turbopack; Chromium 140
    Method
    Loaded all ten prerendered routes from a local next start build in Chromium with JavaScript disabled; each HTTP 200 remained on the localized Loading fallback, so the profile and specimen were not revealed.
    Server rendering
    Hydrates
    Measured ·
    Environment
    macOS 26.6.2; Node 24.19.0; pnpm 10.34.5; Next.js 16.3.0 Turbopack; Chromium 140
    Method
    Inspected the prerendered route response, then loaded the same route with JavaScript enabled and exercised the hydrated client specimen.
    Maintenance
    Stable

    Good fit

    • Short focused tasks that must make the page behind them inactive.

    Avoid when

    • Consequential confirmations that require an explicit safe decision.

    Verification checklist

    Try these actions in the lab, then check the same behaviours in your agent’s result. Adapt the example names to your interface.

    1. 1. Do this

      Open the dialog and cycle through its controls with Tab and Shift+Tab.

      Expected result

      Focus stays inside the modal while it is open, and the page behind it cannot be used.

    2. 2. Do this

      Submit an invalid value, then correct it without closing the dialog.

      Expected result

      The dialog stays open, identifies the field to correct and preserves the rest of your input.

    3. 3. Do this

      Try Cancel and, when cancellation is allowed, Escape after editing a value.

      Expected result

      Each dismissal follows the stated rule for unsaved changes and returns focus to the opening control.

    Full contract
    1. 1The page behind the dialog is inert
    2. 2The dialog has an accessible title and description
    3. 3Focus is contained and then restored
    4. 4Every dismissal path handles unsaved work safely

    Technical details

    Behaviors

    • Contain focus

      While modal, keyboard focus stays inside the surface until it closes.

    • Dismiss with Escape

      Escape closes the temporary surface and returns focus to a sensible control.

    States

    • Dialog closed

      Dialog closed

    • Dialog open

      Dialog open

    State transitions
    • Dialog closed → Dialog open

      The edit trigger is activated and focus enters the bounded task.

    • Dialog open → Dialog closed

      The task is saved or cancelled, or Escape safely closes it, then focus returns to the trigger.

    Test scenarios

    Context
    A team member card opens a short form to edit role and display name.
    Mission
    Open the dialog, tab through every control, cancel with Escape, and verify focus returns to Edit member.
    Primary state
    The edit form opens with its title announced and focus on the first useful field.
    Edge case
    A validation error keeps the dialog open, links the message to the invalid field, and moves focus only when submission fails.

    Visual signals

    • Surface above a dimmed page
    • Clear title and task content
    • Visible close or cancel path

    Behavioral signals

    • Background becomes inert
    • Focus stays inside
    • Focus returns to the opener after closing

    Accessibility

    Role
    dialog[aria-modal=true]
    Accessible name
    The primary control or named region for Modal dialog has a stable accessible name from visible text or an explicit programmatic label; placeholder text and tooltips are not names.
    Focus
    Opening moves focus inside, Tab cannot reach the inert page, and closing restores focus to the logical opener.
    Dismissal
    Cancel, the named close control, and Escape close without saving; outside press is enabled only when accidental loss is harmless.
    Scroll
    Background scrolling is locked while the modal is open. Overflow scrolls inside the surface and the focused control remains visible.
    Announcement
    Assistive technology receives the dialog role, accessible title, description, and validation updates.
    Keyboard
    • Tab and Shift+Tab cycle inside the dialog
    • Escape closes when cancellation is safe
    • Enter submits only from the intended control

    Bindings

    Open the HTML, ARIA, Radix, and shadcn matrix
    • Dialog.Root

      implementationKind
      radix
      nativeElement
      Not applicable
      ariaPattern
      dialog
      radixPrimitive
      Dialog
      shadcnRecipe
      Dialog
      runtimeDependency
      @radix-ui/react-dialog@1.1.19
      packageName
      @radix-ui/react-dialog
      exportName
      Dialog.Root
      exactVersion
      1.1.19
      status
      verified
      sourceId
      source-ui-radix-dialog
      deprecationStatus
      active
      replacement
      Not applicable
      validFrom
      Not applicable
      validUntil
      Not applicable

      Equivalence caveat: Radix supplies modal focus mechanics; labeling, wording, layout, and product testing remain application work.

      Verify binding source

    Sources

    • WAI-ARIA APG: Dialog Modal Pattern
      sourceId
      source-ui-aria-dialog-modal
      kind
      documentation
      canonicalUrl
      https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
      publisher
      W3C WAI
      sourceRevision
      http-last-modified:2026-07-09T07:07:35Z
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:4282d2eeb383c717ba41f52f0db1643fb3eb9acc33fa3879ef817e27c162453e
      status
      verified

      Claim covered: Modal dialog: informative APG guidance for the modal dialog pattern: roles, states, relationships, and keyboard interaction.

    • Radix Primitives: Dialog
      sourceId
      source-ui-radix-dialog
      kind
      documentation
      canonicalUrl
      https://www.radix-ui.com/primitives/docs/components/dialog
      publisher
      Radix Primitives
      sourceRevision
      http-etag:W/"df76fcc1be71ddeff0677a09beda6d7e"
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:068577fa4c5cf2ccc711b9e97e2473ed516e4840e220f2b2f03c552d346fc92f
      status
      verified

      Claim covered: Modal dialog: documented parts, state APIs, interaction behavior, and implementation limits for Radix Dialog.

    • WAI-ARIA 1.2: Roles Model
      sourceId
      source-ui-wai-aria-roles
      kind
      standard
      canonicalUrl
      https://www.w3.org/TR/wai-aria-1.2/#roles
      publisher
      W3C WAI
      sourceRevision
      W3C-REC-wai-aria-1.2-20230606
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:c0fea16fc747779569ab754d2d25bca3e2b7e8a673b8ef5362aeb9ebc73a4849
      status
      verified

      Claim covered: Modal dialog: normative ARIA role definitions and constraints for the stated accessible role.

    • WCAG 2.2: Focus Appearance
      sourceId
      source-ui-wcag-understanding-focus-appearance
      kind
      documentation
      canonicalUrl
      https://www.w3.org/WAI/WCAG22/Understanding/focus-appearance.html
      publisher
      W3C WAI
      sourceRevision
      http-last-modified:2026-07-02T10:07:49Z
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:fdcf316a1f0e3cc758eda9618322d132862124ff0a3f3b1a3acbf20daf804ff0
      status
      verified

      Claim covered: Modal dialog: informative WCAG guidance for evaluating visible keyboard focus appearance.

    • WAI-ARIA APG: Button Pattern
      sourceId
      source-ui-aria-button
      kind
      documentation
      canonicalUrl
      https://www.w3.org/WAI/ARIA/apg/patterns/button/
      publisher
      W3C WAI
      sourceRevision
      http-last-modified:2026-07-09T07:07:36Z
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:863329ea659a53439b0953eec0bd0af7c6219e372d0e878f75e57d263924704c
      status
      verified

      Claim covered: Modal dialog: informative APG guidance for the button pattern: roles, states, relationships, and keyboard interaction.