Dialog

A dialog asks a question the reader must answer before going on, and keeps the rest of the page inert until it closes. Its variant sets how much screen the question takes: basic for one decision, full screen for a series of tasks. A form inside it closes the dialog and names the button that did, with no handler to write. Each button below opens a different dialog.

New event
New event
All day
Save
Rename
Rename file
Cancel Rename
Keyboard shortcuts
  • Esc closes this dialog.
  • Tab moves to the next control, and wraps from the last back to the first.
  • Shift+Tab moves back.
  • Enter or Space presses the focused button.
While a dialog is open, the page behind it ignores your keyboard and your pointer.
Got it
Discard draft delete
Discard this draft?
Your reply to Priya will be deleted, all four paragraphs of it. You can't undo this.
Keep editing Discard
Notifications
Mentions Replies to my comments A weekly summary Someone opens a dialog
Cancel Save
lock
Unlock private notes
Your private notes stay locked until you enter your passcode.
Cancel Unlock
Read the terms
Terms of play
These terms cover the buttons at the top of this page. By pressing one, you agree that you read them, or at least scrolled past them.
  1. Every button here opens a real dialog. None of them is a picture of one.
  2. Anything typed into a dialog here stays on this page. Each form closes its dialog and keeps nothing.
  3. Escape closes every dialog here, whatever it asked.
  4. While a dialog is open, the rest of the page is inert. It cannot be clicked, focused, or scrolled.
  5. Tab moves through the controls in this dialog and wraps at the end, rather than wandering off into the page behind it.
  6. This text scrolls because it is taller than the dialog. The headline and the buttons stay where they are.
  7. The lines at the top and bottom of this text show that there is more of it to read.
  8. Each dialog wears one of the site's demo themes. The component is the same in all of them.
  9. The button that closes this dialog becomes its return value: accept or decline. Neither has any consequence.
Decline Accept
Change ringtone
Phone ringtone
Chirp Marimba Rustling leaves Tongue click None
Cancel OK
schedule
Still there?
For your security, you'll be signed out in two minutes. Anything you haven't saved stays on this device.
Sign out Stay signed in
About Chameleon
About Chameleon
Chameleon is a library of Material 3 Expressive components for the web, React, and Blazor.
This dialog is one of them. The others on this page wear other demo themes, and every one of them is the same component.
Close
New message
Send
How many stars?
One star if you've seen enough dialogs, five if you'd like to see them all again.
Not now Send rating
photo_camera
Allow camera access?
Scan a receipt or a whiteboard straight into a note. You can change this later in Settings.
Not now Allow
Invite a teammate
They'll get an email from you with a link that works for seven days.
Cancel Send invitation
call_end
Leave the call?
The other four people can carry on without you. Your invitation still works if you want to rejoin.
Stay Leave
Report a problem
Include a screenshot
Cancel Send report

Reference docs⁠

BlazorReactWebOverviewExamplesAPIStylingAccessibility

Choosing a pop-up surface⁠

Five kinds of surface open over the page for a moment. Each suits a different job:

  • Dialog: a question the reader must answer before going on, such as Discard unsaved changes?
  • Popover: extra content opened from a control and dismissed by clicking away, such as a small settings panel.
  • Menu: a short list of commands opened from a button, such as Rename, Duplicate, Delete.
  • Plain tooltip: a short label shown on hover or focus, such as what an icon button does.
  • Rich tooltip: a heading, a few lines of text and an optional action shown next to the element it describes, such as what a new feature does.

Three jobs belong elsewhere. A message about something that just happened is a toast, content that stays on the page is a card, and a short set of creation actions opened from a floating button is a FAB menu.

Choosing a variant⁠

Two variants set how much of the screen a dialog takes, from least to most:

  • Basic: one decision or a short task, such as confirming a deletion or renaming a file.
  • Full screen: a series of tasks, such as filling in a new event's title, time, and guests on a phone.

Built in⁠

  • The page behind an open dialog is inert, and its scrolling is locked until the dialog closes.
  • Tab and Shift+Tab stay inside the dialog, wrapping from its last control to its first.
  • Escape and a click on the scrim close it, each firing a cancelable cancel event first; ignore-escape-key and ignore-scrim-click turn either off.
  • A <form method="dialog"> in its content closes it and sets return-value to the value of the button that submitted it.
  • Content taller than the dialog scrolls inside it, with a shadow or a divider at the edge that has more (scroll-indicator).
  • The full-screen variant draws its own close button and moves the actions into its headline bar (actions-placement).

Hidden content renders when first shown⁠

A dialog's panel, headline, content, and actions do not exist until it first opens. Each opening starts like the first, scrolled to the top. Your content stays as it was, so a half-filled form is still half filled, and returnValue stays readable after the dialog closes. After you open the dialog, wait for updateComplete and everything is there for your code to reach at once. See Hidden content renders when first shown.

Starting fresh each time⁠

A dialog never clears what your app put in it, so a form the user abandoned is still filled when the dialog opens again. If each opening should start empty, reset the content when the dialog reports it has closed.

dialog.addEventListener("toggle", (event) => {
  if (event.newState === "closed") dialog.querySelector("form")?.reset();
});
content_copy

React and Blazor use onToggle and OnToggle; see Starting each opening empty.

Using dialogs well⁠

  • Open a dialog only for a question the reader must answer now; show anything they can ignore in a Popover or a Menu.
  • Give every dialog a headline that states its question, or an aria-label when it has no headline.
  • Set type to alert only for an important message that needs a response, such as confirming a destructive action.
  • Put the confirming action last, after the one that dismisses: Cancel, then Delete.
  • Put autofocus on the control that should take focus when the dialog opens, usually the safest action.
  • Open a dialog over another dialog only from a full-screen one.

These rules follow Material 3 Expressive's guidance for dialogs, on material.io.

Variants⁠

variant has two values. basic, the default, can show an icon slot above its headline. full-screen fills the viewport, draws a close button in its headline bar, and puts the actions there too; set no-close-button to remove the close button. When to choose each is in Choosing a variant.

Opening and closing⁠

Set open, or call show(), to open a dialog; clear open, or call close(), to close it. close() takes an optional value, which becomes return-value. Each change fires a beforetoggle event before its animation, and a toggle event after it; both carry oldState and newState. Cancel beforetoggle to keep the dialog shut when newState is "open", or to keep it open when newState is "closed". A listener on the dialog hears only its own beforetoggle and toggle, never those of an element inside it.

Dismissing⁠

Escape and a click on the scrim both fire cancel on the dialog, then close it with the usual beforetoggle and toggle; cancel that cancel event to keep it open. cancel does not bubble, so listen on the dialog itself. Set ignore-escape-key or ignore-scrim-click to turn either path off, and then no cancel fires for it. Keep at least one way out: with both set, and no-close-button on a full-screen dialog, only the controls you put inside it can close it.

Forms⁠

Put a <form method="dialog"> in the content slot, and give each button in the actions slot the form's id in its form attribute, a type of submit, and a value. Submitting the form closes the dialog, and return-value becomes the value of the button that submitted it; read it in a toggle listener once newState is "closed". A form that fails validation does not submit, so the dialog stays open. The preview blocks form submission in some browsers, so each button here also calls close() with its value; on your own page, the form alone closes the dialog.

Alert dialogs⁠

With type set to alert, screen readers announce the dialog as an alert dialog rather than a plain one. Leave type unset for every other dialog; when to use it is in Using dialogs well.

Actions placement⁠

actions-placement moves the actions slot independently of the variant. auto, the default, puts the actions in the footer row of a basic dialog and in the headline bar of a full-screen one. bottom and headline put them in one place whatever the variant. Slot each button directly; they sit at the end of the row and wrap when space runs short.

Animation⁠

animation sets how a dialog appears and leaves: fade, slide, or none. Omit it and the dialog takes the animation from your style configuration, which is fade unless you have changed it. A reader who asks for reduced motion gets no animation, whatever the setting.

Scroll indicator⁠

Content taller than the dialog scrolls inside it, vertically only. scroll-indicator marks the edge that has more to show: shadow, divider, or none. Omit it and the dialog takes the indicator from your style configuration, which is shadow unless you have changed it.

Properties⁠

PropertyAttributeTypeDescription
actionsPlacementactions-placementauto, bottom, headlineDialogActionsPlacementDialogActionsPlacement.Auto, .Bottom, .Headlinedefault DialogActionsPlacement.AutoWhere the actions slot appears, independently of variant. auto puts it in the headline bar for full-screen and in the footer row for basic. See Actions placement.
animationanimationfade, none, slideDialogAnimationDialogAnimation.Fade, .None, .Slidedefault DialogAnimation.Fade, from the style configurationSets how the dialog animates open and closed. See Animation.
ignoreEscapeKeyignore-escape-keybooleandefault falseIf set to true, pressing the Escape key will not close the dialog. See Dismissing.
ignoreScrimClickignore-scrim-clickbooleandefault falseIf set to true, clicking on the scrim (backdrop) will not close the dialog. See Dismissing.
maskContentmask-contentbooleanClips the content to the component's shape, so anything that extends past a rounded corner is cut off.
noCloseButtonno-close-buttonbooleandefault falseHides the built-in close button in the full-screen variant's headline. Set it alongside ignore-scrim-click and ignore-escape-key when the application owns every exit path — the dialog then cannot be dismissed except through content the host supplies itself. See Variants, Dismissing.
noFocusTrapno-focus-trapbooleandefault falseLets Tab leave the dialog: pressing Tab on its last focusable element moves focus out to the browser, such as the address bar. Keeping focus inside is recommended for accessibility, so turn this on only when the dialog is more accessible without it.
openopenbooleandefault falseOpens the dialog when set to true and closes it when set to false. Returns to false whenever the dialog closes, including by Escape or a scrim click, and when a beforetoggle listener cancels the opening. See Opening and closing.
returnValuereturn-valuestringThe dialog's return value, usually naming the button that closed it. Set by close(value) or by the submit button's value in a <form method="dialog">; unchanged by Escape, a scrim click or the close button. The return-value attribute presets it, which is the value a bare close() adopts.See MDN: HTMLDialogElement.returnValue. See Opening and closing, Forms.
scrollIndicatorscroll-indicatordivider, none, shadowScrollIndicatorScrollIndicator.Divider, .None, .Shadowdefault ScrollIndicator.Shadow, from the style configurationMarks the top and bottom edges of the content while it can scroll further. The content scrolls vertically only. See Scroll indicator.
typetypestringThe type of dialog for accessibility. Set this to alert to announce a dialog as an alert dialog. See Alert dialogs.
variantvariantbasic, full-screenDialogVariantDialogVariant.Basic, .FullScreendefault DialogVariant.BasicSets how the dialog is laid out. Use basic for standard dialogs, full-screen for complex forms on mobile. See Variants.

Slots⁠

SlotDescription
iconAn icon above the headline, in the basic variant only. Hidden from screen readers.
headlineThe dialog's title, which screen readers announce as its name. Without a headline, set aria-label.
contentMain scrollable content area
actionsThe dialog's action buttons, in the footer or, for full-screen or actions-placement="headline", the headline bar.

Events⁠

EventTypeDetailDescription
beforetoggleToggleEvent—Before the opening or closing animation starts. Cancelable: calling preventDefault() leaves the dialog as it is. newState is "open" or "closed". It bubbles, is composed, and is cancelable.
toggleToggleEvent—After the opening or closing animation completes. newState is "open" or "closed". It bubbles and is composed.
cancelEvent—Fires when a scrim click or the Escape key dismisses the dialog. Cancel it to keep the dialog open. Not fired for a route that ignore-scrim-click or ignore-escape-key turns off. It is cancelable.

Methods⁠

MethodReturnsDescription
close(returnValue?: string)Promise<void>Closes the dialog and fires a cancelable beforetoggle event. After a dialog's animation, a toggle event is fired.
show()Promise<void>Opens the dialog and fires a cancelable beforetoggle event. After a dialog's animation, a toggle event is fired.Add an autofocus attribute to a child of the dialog that should receive focus after opening.

show() resolves after the toggle that reports "open", and close() after the one that reports "closed". A second close() while one is in flight waits for the first.

Props⁠

PropTypeDescription
actionsPlacementDialogActionsPlacementTypeDialogActionsPlacement.Auto, .Bottom, .Headlinedefault DialogActionsPlacement.AutoWhere the slot="actions" child appears, independently of variant. auto puts it in the headline bar for full-screen and in the footer row for basic. See Actions placement.
animationDialogAnimationTypeDialogAnimation.Fade, .None, .Slidedefault DialogAnimation.Fade, from the style configurationSets how the dialog animates open and closed. See Animation.
ignoreEscapeKeybooleandefault falseIf set to true, pressing the Escape key will not close the dialog. See Dismissing.
ignoreScrimClickbooleandefault falseIf set to true, clicking on the scrim (backdrop) will not close the dialog. See Dismissing.
maskContentbooleanClips the content to the component's shape, so anything that extends past a rounded corner is cut off.
noCloseButtonbooleandefault falseHides the built-in close button in the full-screen variant's headline. Set it alongside ignoreScrimClick and ignoreEscapeKey when the application owns every exit path — the dialog then cannot be dismissed except through content the host supplies itself. See Variants, Dismissing.
noFocusTrapbooleandefault falseLets Tab leave the dialog: pressing Tab on its last focusable element moves focus out to the browser, such as the address bar. Keeping focus inside is recommended for accessibility, so turn this on only when the dialog is more accessible without it.
openbooleandefault falseOpens the dialog when set to true and closes it when set to false. Returns to false whenever the dialog closes, including by Escape or a scrim click, and when a beforetoggle listener cancels the opening. See Opening and closing.
returnValuestringThe dialog's return value, usually naming the button that closed it. Set by close(value) or by the submit button's value in a <form method="dialog">; unchanged by Escape, a scrim click or the close button. The returnValue attribute presets it, which is the value a bare close() adopts.See MDN: HTMLDialogElement.returnValue. See Opening and closing, Forms.
scrollIndicatorScrollIndicatorTypeScrollIndicator.Divider, .None, .Shadowdefault ScrollIndicator.Shadow, from the style configurationMarks the top and bottom edges of the content while it can scroll further. The content scrolls vertically only. See Scroll indicator.
typestringThe type of dialog for accessibility. Set this to alert to announce a dialog as an alert dialog. See Alert dialogs.
variantDialogVariantTypeDialogVariant.Basic, .FullScreendefault DialogVariant.BasicSets how the dialog is laid out. Use basic for standard dialogs, full-screen for complex forms on mobile. See Variants.

Children⁠

ChildDescription
a child with slot="icon"An icon above the headline, in the basic variant only. Hidden from screen readers.
a child with slot="headline"The dialog's title, which screen readers announce as its name. Without a headline, set aria-label.
a child with slot="content"Main scrollable content area
a child with slot="actions"The dialog's action buttons, in the footer or, for full-screen or actions-placement="headline", the headline bar.

Events⁠

PropArgumentDescription
onBeforeToggleToggleEventBefore the opening or closing animation starts. Cancelable: calling preventDefault() leaves the dialog as it is. newState is "open" or "closed". It bubbles, is composed, and is cancelable.
onToggleToggleEventAfter the opening or closing animation completes. newState is "open" or "closed". It bubbles and is composed.
onCancelEventFires when a scrim click or the Escape key dismisses the dialog. Cancel it to keep the dialog open. Not fired for a route that ignoreScrimClick or ignoreEscapeKey turns off. It is cancelable.

Methods⁠

Call these on the element the ref holds.

MethodReturnsDescription
close(returnValue?: string)Promise<void>Closes the dialog and fires a cancelable beforetoggle event. After a dialog's animation, a toggle event is fired.
show()Promise<void>Opens the dialog and fires a cancelable beforetoggle event. After a dialog's animation, a toggle event is fired.Add an autofocus attribute to a child of the dialog that should receive focus after opening.

show() resolves after the toggle that reports "open", and close() after the one that reports "closed". A second close() while one is in flight waits for the first.

Parameters⁠

ParameterTypeDescription
ActionsPlacementDialogActionsPlacement?DialogActionsPlacement.Auto, .Bottom, .Headlinedefault DialogActionsPlacement.AutoWhere the Actions render fragment appears, independently of Variant. auto puts it in the headline bar for full-screen and in the footer row for basic. See Actions placement.
AnimationDialogAnimation?DialogAnimation.Fade, .None, .Slidedefault DialogAnimation.Fade, from the style configurationSets how the dialog animates open and closed. See Animation.
IgnoreEscapeKeybool?default falseIf set to true, pressing the Escape key will not close the dialog. See Dismissing.
IgnoreScrimClickbool?default falseIf set to true, clicking on the scrim (backdrop) will not close the dialog. See Dismissing.
MaskContentbool?Clips the content to the component's shape, so anything that extends past a rounded corner is cut off.
NoCloseButtonbool?default falseHides the built-in close button in the full-screen variant's headline. Set it alongside IgnoreScrimClick and IgnoreEscapeKey when the application owns every exit path — the dialog then cannot be dismissed except through content the host supplies itself. See Variants, Dismissing.
NoFocusTrapbool?default falseLets Tab leave the dialog: pressing Tab on its last focusable element moves focus out to the browser, such as the address bar. Keeping focus inside is recommended for accessibility, so turn this on only when the dialog is more accessible without it.
Openbool?default falseOpens the dialog when set to true and closes it when set to false. Returns to false whenever the dialog closes, including by Escape or a scrim click, and when a beforetoggle listener cancels the opening. See Opening and closing.
ReturnValuestring?The dialog's return value, usually naming the button that closed it. Set by close(value) or by the submit button's value in a <form method="dialog">; unchanged by Escape, a scrim click or the close button. The ReturnValue attribute presets it, which is the value a bare close() adopts.See MDN: HTMLDialogElement.returnValue. See Opening and closing, Forms.
ScrollIndicatorScrollIndicator?ScrollIndicator.Divider, .None, .Shadowdefault ScrollIndicator.Shadow, from the style configurationMarks the top and bottom edges of the content while it can scroll further. The content scrolls vertically only. See Scroll indicator.
Typestring?The type of dialog for accessibility. Set this to alert to announce a dialog as an alert dialog. See Alert dialogs.
VariantDialogVariant?DialogVariant.Basic, .FullScreendefault DialogVariant.BasicSets how the dialog is laid out. Use basic for standard dialogs, full-screen for complex forms on mobile. See Variants.

Render fragments⁠

ParameterTypeDescription
ActionsRenderFragment?The dialog's action buttons, in the footer or, for full-screen or actions-placement="headline", the headline bar.
ContentRenderFragment?Main scrollable content area
HeadlineRenderFragment?The dialog's title, which screen readers announce as its name. Without a headline, set aria-label.
IconRenderFragment?An icon above the headline, in the basic variant only. Hidden from screen readers.

Event callbacks⁠

ParameterTypeDescription
OnBeforeToggleEventCallback<ToggleEventArgs>Before the opening or closing animation starts. Cancelable: calling preventDefault() leaves the dialog as it is. newState is "open" or "closed". It bubbles, is composed, and is cancelable.
OnToggleEventCallback<ToggleEventArgs>After the opening or closing animation completes. newState is "open" or "closed". It bubbles and is composed.
OnCancelEventCallbackFires when a scrim click or the Escape key dismisses the dialog. Cancel it to keep the dialog open. Not fired for a route that IgnoreScrimClick or IgnoreEscapeKey turns off. It is cancelable.

Inputs⁠

InputTypeDescription
actionsPlacementDialogActionsPlacementTypeDialogActionsPlacement.Auto, .Bottom, .Headlinedefault DialogActionsPlacement.AutoWhere the actions slot appears, independently of variant. auto puts it in the headline bar for full-screen and in the footer row for basic. See Actions placement.
animationDialogAnimationTypeDialogAnimation.Fade, .None, .Slidedefault DialogAnimation.Fade, from the style configurationSets how the dialog animates open and closed. See Animation.
ignoreEscapeKeybooleandefault falseIf set to true, pressing the Escape key will not close the dialog. See Dismissing.
ignoreScrimClickbooleandefault falseIf set to true, clicking on the scrim (backdrop) will not close the dialog. See Dismissing.
maskContentbooleanClips the content to the component's shape, so anything that extends past a rounded corner is cut off.
noCloseButtonbooleandefault falseHides the built-in close button in the full-screen variant's headline. Set it alongside ignoreScrimClick and ignoreEscapeKey when the application owns every exit path — the dialog then cannot be dismissed except through content the host supplies itself. See Variants, Dismissing.
noFocusTrapbooleandefault falseLets Tab leave the dialog: pressing Tab on its last focusable element moves focus out to the browser, such as the address bar. Keeping focus inside is recommended for accessibility, so turn this on only when the dialog is more accessible without it.
openbooleandefault falseOpens the dialog when set to true and closes it when set to false. Returns to false whenever the dialog closes, including by Escape or a scrim click, and when a beforetoggle listener cancels the opening. See Opening and closing.
returnValuestringThe dialog's return value, usually naming the button that closed it. Set by close(value) or by the submit button's value in a <form method="dialog">; unchanged by Escape, a scrim click or the close button. The returnValue attribute presets it, which is the value a bare close() adopts.See MDN: HTMLDialogElement.returnValue. See Opening and closing, Forms.
scrollIndicatorScrollIndicatorTypeScrollIndicator.Divider, .None, .Shadowdefault ScrollIndicator.Shadow, from the style configurationMarks the top and bottom edges of the content while it can scroll further. The content scrolls vertically only. See Scroll indicator.
typestringThe type of dialog for accessibility. Set this to alert to announce a dialog as an alert dialog. See Alert dialogs.
variantDialogVariantTypeDialogVariant.Basic, .FullScreendefault DialogVariant.BasicSets how the dialog is laid out. Use basic for standard dialogs, full-screen for complex forms on mobile. See Variants.

Content projection⁠

ContentDescription
an element with slot="icon"An icon above the headline, in the basic variant only. Hidden from screen readers.
an element with slot="headline"The dialog's title, which screen readers announce as its name. Without a headline, set aria-label.
an element with slot="content"Main scrollable content area
an element with slot="actions"The dialog's action buttons, in the footer or, for full-screen or actions-placement="headline", the headline bar.

Outputs⁠

OutputEventDescription
cwBeforeToggleToggleEventBefore the opening or closing animation starts. Cancelable: calling preventDefault() leaves the dialog as it is. newState is "open" or "closed". It bubbles, is composed, and is cancelable.
cwToggleToggleEventAfter the opening or closing animation completes. newState is "open" or "closed". It bubbles and is composed.
cwCancelEventFires when a scrim click or the Escape key dismisses the dialog. Cancel it to keep the dialog open. Not fired for a route that ignoreScrimClick or ignoreEscapeKey turns off. It is cancelable.

Props⁠

PropTypeDescription
actionsPlacementDialogActionsPlacementTypeDialogActionsPlacement.Auto, .Bottom, .Headlinedefault DialogActionsPlacement.AutoWhere the actions slot appears, independently of variant. auto puts it in the headline bar for full-screen and in the footer row for basic. See Actions placement.
animationDialogAnimationTypeDialogAnimation.Fade, .None, .Slidedefault DialogAnimation.Fade, from the style configurationSets how the dialog animates open and closed. See Animation.
ignoreEscapeKeybooleandefault falseIf set to true, pressing the Escape key will not close the dialog. See Dismissing.
ignoreScrimClickbooleandefault falseIf set to true, clicking on the scrim (backdrop) will not close the dialog. See Dismissing.
maskContentbooleanClips the content to the component's shape, so anything that extends past a rounded corner is cut off.
noCloseButtonbooleandefault falseHides the built-in close button in the full-screen variant's headline. Set it alongside ignoreScrimClick and ignoreEscapeKey when the application owns every exit path — the dialog then cannot be dismissed except through content the host supplies itself. See Variants, Dismissing.
noFocusTrapbooleandefault falseLets Tab leave the dialog: pressing Tab on its last focusable element moves focus out to the browser, such as the address bar. Keeping focus inside is recommended for accessibility, so turn this on only when the dialog is more accessible without it.
openbooleandefault falseOpens the dialog when set to true and closes it when set to false. Returns to false whenever the dialog closes, including by Escape or a scrim click, and when a beforetoggle listener cancels the opening. See Opening and closing.
returnValuestringThe dialog's return value, usually naming the button that closed it. Set by close(value) or by the submit button's value in a <form method="dialog">; unchanged by Escape, a scrim click or the close button. The returnValue attribute presets it, which is the value a bare close() adopts.See MDN: HTMLDialogElement.returnValue. See Opening and closing, Forms.
scrollIndicatorScrollIndicatorTypeScrollIndicator.Divider, .None, .Shadowdefault ScrollIndicator.Shadow, from the style configurationMarks the top and bottom edges of the content while it can scroll further. The content scrolls vertically only. See Scroll indicator.
typestringThe type of dialog for accessibility. Set this to alert to announce a dialog as an alert dialog. See Alert dialogs.
variantDialogVariantTypeDialogVariant.Basic, .FullScreendefault DialogVariant.BasicSets how the dialog is laid out. Use basic for standard dialogs, full-screen for complex forms on mobile. See Variants.

Slots⁠

SlotDescription
actionsThe dialog's action buttons, in the footer or, for full-screen or actions-placement="headline", the headline bar.
contentMain scrollable content area
headlineThe dialog's title, which screen readers announce as its name. Without a headline, set aria-label.
iconAn icon above the headline, in the basic variant only. Hidden from screen readers.

Events⁠

EventTypeDescription
beforeToggleToggleEventBefore the opening or closing animation starts. Cancelable: calling preventDefault() leaves the dialog as it is. newState is "open" or "closed". It bubbles, is composed, and is cancelable.
toggleToggleEventAfter the opening or closing animation completes. newState is "open" or "closed". It bubbles and is composed.
cancelEventFires when a scrim click or the Escape key dismisses the dialog. Cancel it to keep the dialog open. Not fired for a route that ignoreScrimClick or ignoreEscapeKey turns off. It is cancelable.

Props⁠

PropTypeDescription
actionsPlacementDialogActionsPlacementTypeDialogActionsPlacement.Auto, .Bottom, .Headlinedefault DialogActionsPlacement.AutoWhere the actionsSnippet snippet appears, independently of variant. auto puts it in the headline bar for full-screen and in the footer row for basic. See Actions placement.
animationDialogAnimationTypeDialogAnimation.Fade, .None, .Slidedefault DialogAnimation.Fade, from the style configurationSets how the dialog animates open and closed. See Animation.
ignoreEscapeKeybooleandefault falseIf set to true, pressing the Escape key will not close the dialog. See Dismissing.
ignoreScrimClickbooleandefault falseIf set to true, clicking on the scrim (backdrop) will not close the dialog. See Dismissing.
maskContentbooleanClips the content to the component's shape, so anything that extends past a rounded corner is cut off.
noCloseButtonbooleandefault falseHides the built-in close button in the full-screen variant's headline. Set it alongside ignoreScrimClick and ignoreEscapeKey when the application owns every exit path — the dialog then cannot be dismissed except through content the host supplies itself. See Variants, Dismissing.
noFocusTrapbooleandefault falseLets Tab leave the dialog: pressing Tab on its last focusable element moves focus out to the browser, such as the address bar. Keeping focus inside is recommended for accessibility, so turn this on only when the dialog is more accessible without it.
openbooleandefault falseOpens the dialog when set to true and closes it when set to false. Returns to false whenever the dialog closes, including by Escape or a scrim click, and when a beforetoggle listener cancels the opening. See Opening and closing.
returnValuestringThe dialog's return value, usually naming the button that closed it. Set by close(value) or by the submit button's value in a <form method="dialog">; unchanged by Escape, a scrim click or the close button. The returnValue attribute presets it, which is the value a bare close() adopts.See MDN: HTMLDialogElement.returnValue. See Opening and closing, Forms.
scrollIndicatorScrollIndicatorTypeScrollIndicator.Divider, .None, .Shadowdefault ScrollIndicator.Shadow, from the style configurationMarks the top and bottom edges of the content while it can scroll further. The content scrolls vertically only. See Scroll indicator.
typestringThe type of dialog for accessibility. Set this to alert to announce a dialog as an alert dialog. See Alert dialogs.
variantDialogVariantTypeDialogVariant.Basic, .FullScreendefault DialogVariant.BasicSets how the dialog is laid out. Use basic for standard dialogs, full-screen for complex forms on mobile. See Variants.

Snippets⁠

SnippetDescription
iconSnippetAn icon above the headline, in the basic variant only. Hidden from screen readers.
headlineSnippetThe dialog's title, which screen readers announce as its name. Without a headline, set aria-label.
contentSnippetMain scrollable content area
actionsSnippetThe dialog's action buttons, in the footer or, for full-screen or actions-placement="headline", the headline bar.

Events⁠

PropTypeDescription
onBeforeToggleToggleEventBefore the opening or closing animation starts. Cancelable: calling preventDefault() leaves the dialog as it is. newState is "open" or "closed". It bubbles, is composed, and is cancelable.
onToggleToggleEventAfter the opening or closing animation completes. newState is "open" or "closed". It bubbles and is composed.
onCancelEventFires when a scrim click or the Escape key dismisses the dialog. Cancel it to keep the dialog open. Not fired for a route that ignoreScrimClick or ignoreEscapeKey turns off. It is cancelable.

Each attribute value has its own tokens; a cell shows its token's value, and selecting the cell shows the token's fallback path, with each name and value ready to copy. For example, the basic column's container-color row is --ct-dialog-basic-container-color, which defaults to --ct-sys-color-surface-container-high.

Variant⁠

Namebasicfull-screen
container-color--ct-sys-color-surface-container-high --ct-dialog-basic-container-color--ct-sys-color-surface-container-high --ct-dialog-full-screen-container-color
elevation3 --ct-dialog-basic-elevation—
headline-color--ct-sys-color-on-surface --ct-dialog-basic-headline-color—
headline-font--ct-sys-typescale-headline-small-font --ct-dialog-basic-headline-font--ct-sys-typescale-headline-large-font --ct-dialog-full-screen-headline-font
headline-line-height--ct-sys-typescale-headline-small-line-height --ct-dialog-basic-headline-line-height--ct-sys-typescale-headline-large-line-height --ct-dialog-full-screen-headline-line-height
headline-size--ct-sys-typescale-headline-small-size --ct-dialog-basic-headline-size--ct-sys-typescale-headline-large-size --ct-dialog-full-screen-headline-size
headline-tracking--ct-sys-typescale-headline-small-tracking --ct-dialog-basic-headline-tracking--ct-sys-typescale-headline-large-tracking --ct-dialog-full-screen-headline-tracking
headline-weight--ct-sys-typescale-headline-small-weight --ct-dialog-basic-headline-weight--ct-sys-typescale-headline-large-weight --ct-dialog-full-screen-headline-weight
heightfit-content --ct-dialog-basic-height—
icon-color--ct-sys-color-secondary --ct-dialog-basic-icon-color—
icon-size24px --ct-dialog-basic-icon-size—
max-heightsame as height --ct-dialog-basic-max-height—
max-widthsame as width --ct-dialog-basic-max-width—
min-heightsame as height --ct-dialog-basic-min-height—
min-widthsame as width --ct-dialog-basic-min-width—
outline-colortransparent --ct-dialog-basic-outline-color—
outline-opacity1 --ct-dialog-basic-outline-opacity—
outline-width0px --ct-dialog-basic-outline-width—
scrim-blur0px --ct-dialog-basic-scrim-blur—
scrim-color--ct-sys-color-scrim --ct-dialog-basic-scrim-color—
scrim-opacity0.32 --ct-dialog-basic-scrim-opacity—
supporting-text-color--ct-sys-color-on-surface-variant --ct-dialog-basic-supporting-text-color—
supporting-text-font--ct-sys-typescale-body-medium-font --ct-dialog-basic-supporting-text-font--ct-sys-typescale-label-large-font --ct-dialog-full-screen-supporting-text-font
supporting-text-line-height--ct-sys-typescale-body-medium-line-height --ct-dialog-basic-supporting-text-line-height--ct-sys-typescale-label-large-line-height --ct-dialog-full-screen-supporting-text-line-height
supporting-text-size--ct-sys-typescale-body-medium-size --ct-dialog-basic-supporting-text-size--ct-sys-typescale-label-large-size --ct-dialog-full-screen-supporting-text-size
supporting-text-tracking--ct-sys-typescale-body-medium-tracking --ct-dialog-basic-supporting-text-tracking--ct-sys-typescale-label-large-tracking --ct-dialog-full-screen-supporting-text-tracking
supporting-text-weight--ct-sys-typescale-body-medium-weight --ct-dialog-basic-supporting-text-weight--ct-sys-typescale-label-large-weight --ct-dialog-full-screen-supporting-text-weight
width48px)) --ct-dialog-basic-width—

Indicator⁠

Namedividershadow
color--ct-scroll-region---ct-sys-color-outline-variant --ct-scroll-region-divider-color—
level--ct-scroll-region-—3 --ct-scroll-region-shadow-level
opacity--ct-scroll-region-—0.8 --ct-scroll-region-shadow-opacity
thickness--ct-scroll-region-1px --ct-scroll-region-divider-thickness—
thickness-block--ct-scroll-region-—24px --ct-scroll-region-shadow-thickness-block
thickness-inline--ct-scroll-region-—24px --ct-scroll-region-shadow-thickness-inline

Names and states⁠

A dialog is announced as a modal dialog and follows the WAI-ARIA Authoring Practices: Dialog (Modal) pattern.

  • The headline's text names the dialog. A dialog with no headline takes its name from an aria-label on it; with neither, it has no name, so give it one or the other.
  • aria-label is the only ARIA attribute a dialog accepts. Any other aria-* attribute, and role, has no effect.
  • An alert dialog is announced with an urgent tone that a plain dialog lacks.
  • The headline is announced as a level-two heading, so slot the headline as plain text in a <div> or <span>, never as a heading element.
  • The icon slot is hidden from screen readers, so an icon adds nothing to the name or description; put any meaning in the headline.
  • While its content overflows, the scrolling region is a named region landmark. The headline names it, or else the dialog's aria-label, or else the English words "Dialog content", which are not localized.
  • The full-screen variant's close button is named by the localized word "Close".
  • For content the reader can ignore, a Popover or a Menu suits better; see Choosing a pop-up surface.

Keyboard and focus⁠

Key Action
Escape Fires cancel, then closes the dialog; does nothing with ignore-escape-key set
Tab Moves focus to the next control, from the last one back to the first
Shift+Tab Moves focus to the previous control, from the first one back to the last
The arrow keys, Page Up, Page Down, Space, Home, End Scroll the content while its scrolling region has focus
  • On opening, focus moves to the first control in the dialog, or to the element that carries autofocus. Put autofocus on the safest action. With nothing focusable inside, the dialog itself takes focus.
  • The page behind the dialog is inert while it is open, so Tab never reaches it. no-focus-trap removes the wrap, and Tab then moves on to the browser's own controls.
  • Closing the dialog, by any route, returns focus to the control that had it before the dialog opened.
  • While its content overflows, the scrolling region is a Tab stop, so a keyboard user can scroll it.
  • The controls inside draw their own focus rings.

Pointer and touch⁠

  • A click or tap on the scrim fires cancel, then closes the dialog, unless ignore-scrim-click is set. A click inside the dialog, or inside a popover it contains, is not a scrim click.
  • The only control the dialog draws itself is the full-screen variant's close button, a small icon button, whose target size against WCAG 2.5.8 (24 by 24 pixels) is the icon button's. Every other target is a control you slot in.

Display settings⁠

  • Forced colors: the dialog takes a 2-pixel outline in the system's text color, and the scrim drops its blur and keeps its opacity.
  • Reduced motion: the open and close animation becomes none, whatever animation says.

Standards⁠

With its defaults, a dialog meets two WCAG 2.2 success criteria:

  • 2.1.2 No Keyboard Trap (A)
  • 2.4.7 Focus Visible (AA)

Four more depend on how you use it:

  • 2.4.3 Focus Order (A): put autofocus on the safest action, and check that focus returns to the control that opened the dialog when it closes.
  • 4.1.2 Name, Role, Value (A): give the dialog a headline, or an aria-label when it has none.
  • 2.4.6 Headings and Labels (AA): write a headline that states the dialog's question or task.
  • 1.3.1 Info and Relationships (A): slot the headline as plain text, since the dialog already makes it a heading.