Search
MaterialComponentsDocs
Components overviewApp barBadgeButtonsButton groupButtonExtended FABFAB menuFABIcon buttonSplit buttonCardCarouselCheckboxChipsDate & time pickersDate pickerTime pickerDialogDividerListLoading & progressLoading indicatorProgressMenuNavigationNavigation barNavigation drawerNavigation railRadio buttonsSearchSelectSheetsBottom sheetSide sheetSliderSnackbarSwitchTabsText fieldToolbarTooltip

Dialog

Focus on a decision. Open a dialog to try its content, actions, and dismissal behavior.

FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

A dialog asks for a decision, or holds a short task, before anything else continues: discard a draft, confirm a deletion, pick a ringtone. It is modal: the page behind it is out of reach until it closes. For a message that needs no answer, use a snackbar.

Usage

The buttons are its actions, and each closes it. layer: 'top' shows it in the browser's top layer, as a native <dialog> above everything else; the web component always is.

Vanilla
import { createDialog } from 'material';

const dialog = createDialog({
  title: 'Discard draft?',
  content: 'Your draft will be deleted.',
  layer: 'top',
  buttons: [
    { text: 'Cancel', variant: 'text', closeDialog: true },
    { text: 'Discard', variant: 'text', closeDialog: true },
  ],
});
document.body.append(dialog.element);

function ask() {
  dialog.open();
}
Web Components
<m-dialog headline="Discard draft?">
  <p>Your draft will be deleted.</p>
  <m-button slot="actions" variant="text">Cancel</m-button>
  <m-button slot="actions" variant="text">Discard</m-button>
</m-dialog>

<script type="module">
  const dialog = document.querySelector('m-dialog');
  dialog.querySelectorAll('m-button[slot="actions"]').forEach((child) => child.addEventListener('click', () => dialog.close()));

  function ask() {
    dialog.show();
  }
</script>
React
import { useState } from 'react';
import { Dialog, Button } from 'material/react';

export function Example() {
  const [open, setOpen] = useState(false);
  const ask = () => setOpen(true);

  return (
    <Dialog open={open} onClose={() => setOpen(false)} headline="Discard draft?">
      <p>Your draft will be deleted.</p>
      <Button slot="actions" variant="text" onClick={() => setOpen(false)}>Cancel</Button>
      <Button slot="actions" variant="text" onClick={() => setOpen(false)}>Discard</Button>
    </Dialog>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MDialog, MButton } from 'material/vue';

const open = ref(false);

function ask() {
  open.value = true;
}
</script>

<template>
  <MDialog :open="open" @close="open = false" headline="Discard draft?">
    <p>Your draft will be deleted.</p>
    <template #actions>
      <MButton variant="text" @click="open = false">Cancel</MButton>
      <MButton variant="text" @click="open = false">Discard</MButton>
    </template>
  </MDialog>
</template>
Svelte
<script lang="ts">
  import { Dialog, Button } from 'material/svelte';

  let open = $state(false);

  function ask() {
    open = true;
  }
</script>

<Dialog open={open} onclose={() => (open = false)} headline="Discard draft?">
  <p>Your draft will be deleted.</p>
  {#snippet actions()}
    <Button variant="text" onclick={() => (open = false)}>Cancel</Button>
    <Button variant="text" onclick={() => (open = false)}>Discard</Button>
  {/snippet}
</Dialog>
SolidJS
import { createSignal } from 'solid-js';
import { Dialog, Button } from 'material/solid';

export function Example() {
  const [open, setOpen] = createSignal(false);
  const ask = () => setOpen(true);

  return (
    <Dialog open={open()} onClose={() => setOpen(false)} headline="Discard draft?">
      <p>Your draft will be deleted.</p>
      <Button slot="actions" variant="text" onClick={() => setOpen(false)}>Cancel</Button>
      <Button slot="actions" variant="text" onClick={() => setOpen(false)}>Discard</Button>
    </Dialog>
  );
}

Examples

Full screen

A full-screen dialog holds a task in a compact window. It has a close button in its header, and is a dialog rather than an alertdialog.

Vanilla
import { createDialog } from 'material';

const dialog = createDialog({
  title: 'New event',
  content: 'Add a title, a time and guests.',
  size: 'fullscreen',
  layer: 'top',
  buttons: [{ text: 'Save', variant: 'text', closeDialog: true }],
});
document.body.append(dialog.element);
Web Components
<m-dialog size="fullscreen" headline="New event">
  <p>Add a title, a time and guests.</p>
  <m-button slot="actions" variant="text">Save</m-button>
</m-dialog>

<script type="module">
  const dialog = document.querySelector('m-dialog');
  dialog.querySelectorAll('m-button[slot="actions"]').forEach((child) => child.addEventListener('click', () => dialog.close()));
</script>
React
import { Dialog, Button } from 'material/react';

export function Example() {
  return (
    <Dialog size="fullscreen" headline="New event">
      <p>Add a title, a time and guests.</p>
      <Button slot="actions" variant="text">Save</Button>
    </Dialog>
  );
}
Vue
<script setup lang="ts">
import { MDialog, MButton } from 'material/vue';
</script>

<template>
  <MDialog size="fullscreen" headline="New event">
    <p>Add a title, a time and guests.</p>
    <template #actions>
      <MButton variant="text">Save</MButton>
    </template>
  </MDialog>
</template>
Svelte
<script lang="ts">
  import { Dialog, Button } from 'material/svelte';
</script>

<Dialog size="fullscreen" headline="New event">
  <p>Add a title, a time and guests.</p>
  {#snippet actions()}
    <Button variant="text">Save</Button>
  {/snippet}
</Dialog>
SolidJS
import { Dialog, Button } from 'material/solid';

export function Example() {
  return (
    <Dialog size="fullscreen" headline="New event">
      <p>Add a title, a time and guests.</p>
      <Button slot="actions" variant="text">Save</Button>
    </Dialog>
  );
}

Only its actions close it

For work that would be lost, the scrim and Escape can be kept from closing it; its actions then have to include a way out.

Vanilla
import { createDialog } from 'material';

const dialog = createDialog({
  title: 'Leave the survey?',
  content: 'Your answers so far will be lost.',
  closeOnOverlayClick: false,
  closeOnEscape: false,
  layer: 'top',
  buttons: [
    { text: 'Stay', variant: 'text', closeDialog: true },
    { text: 'Leave', variant: 'text', closeDialog: true },
  ],
});
document.body.append(dialog.element);
Web Components
<m-dialog headline="Leave the survey?" no-close-on-scrim-click no-close-on-escape>
  <p>Your answers so far will be lost.</p>
  <m-button slot="actions" variant="text">Stay</m-button>
  <m-button slot="actions" variant="text">Leave</m-button>
</m-dialog>

<script type="module">
  const dialog = document.querySelector('m-dialog');
  dialog.querySelectorAll('m-button[slot="actions"]').forEach((child) => child.addEventListener('click', () => dialog.close()));
</script>
React
import { Dialog, Button } from 'material/react';

export function Example() {
  return (
    <Dialog headline="Leave the survey?" noCloseOnScrimClick noCloseOnEscape>
      <p>Your answers so far will be lost.</p>
      <Button slot="actions" variant="text">Stay</Button>
      <Button slot="actions" variant="text">Leave</Button>
    </Dialog>
  );
}
Vue
<script setup lang="ts">
import { MDialog, MButton } from 'material/vue';
</script>

<template>
  <MDialog headline="Leave the survey?" no-close-on-scrim-click no-close-on-escape>
    <p>Your answers so far will be lost.</p>
    <template #actions>
      <MButton variant="text">Stay</MButton>
      <MButton variant="text">Leave</MButton>
    </template>
  </MDialog>
</template>
Svelte
<script lang="ts">
  import { Dialog, Button } from 'material/svelte';
</script>

<Dialog headline="Leave the survey?" noCloseOnScrimClick noCloseOnEscape>
  <p>Your answers so far will be lost.</p>
  {#snippet actions()}
    <Button variant="text">Stay</Button>
    <Button variant="text">Leave</Button>
  {/snippet}
</Dialog>
SolidJS
import { Dialog, Button } from 'material/solid';

export function Example() {
  return (
    <Dialog headline="Leave the survey?" noCloseOnScrimClick noCloseOnEscape>
      <p>Your answers so far will be lost.</p>
      <Button slot="actions" variant="text">Stay</Button>
      <Button slot="actions" variant="text">Leave</Button>
    </Dialog>
  );
}

Subtitle and dividers

divider draws a line above and below the content, for a body that scrolls.

Vanilla
import { createDialog } from 'material';

const dialog = createDialog({
  title: 'Terms of service',
  subtitle: 'Updated September 2026',
  content: 'These terms apply to your use of the service.',
  divider: true,
  layer: 'top',
  buttons: [{ text: 'Accept', variant: 'text', closeDialog: true }],
});
document.body.append(dialog.element);
Web Components
<m-dialog subtitle="Updated September 2026" divider headline="Terms of service">
  <p>These terms apply to your use of the service.</p>
  <m-button slot="actions" variant="text">Accept</m-button>
</m-dialog>

<script type="module">
  const dialog = document.querySelector('m-dialog');
  dialog.querySelectorAll('m-button[slot="actions"]').forEach((child) => child.addEventListener('click', () => dialog.close()));
</script>
React
import { Dialog, Button } from 'material/react';

export function Example() {
  return (
    <Dialog subtitle="Updated September 2026" divider headline="Terms of service">
      <p>These terms apply to your use of the service.</p>
      <Button slot="actions" variant="text">Accept</Button>
    </Dialog>
  );
}
Vue
<script setup lang="ts">
import { MDialog, MButton } from 'material/vue';
</script>

<template>
  <MDialog subtitle="Updated September 2026" divider headline="Terms of service">
    <p>These terms apply to your use of the service.</p>
    <template #actions>
      <MButton variant="text">Accept</MButton>
    </template>
  </MDialog>
</template>
Svelte
<script lang="ts">
  import { Dialog, Button } from 'material/svelte';
</script>

<Dialog subtitle="Updated September 2026" divider headline="Terms of service">
  <p>These terms apply to your use of the service.</p>
  {#snippet actions()}
    <Button variant="text">Accept</Button>
  {/snippet}
</Dialog>
SolidJS
import { Dialog, Button } from 'material/solid';

export function Example() {
  return (
    <Dialog subtitle="Updated September 2026" divider headline="Terms of service">
      <p>These terms apply to your use of the service.</p>
      <Button slot="actions" variant="text">Accept</Button>
    </Dialog>
  );
}

A button's onClick(event, dialog) runs its action, and returning false keeps the dialog open; the web component's actions are buttons of your own. confirm({ message }) asks a question in the dialog and resolves to the answer. Recipes such as confirming a deletion or a form that validates before it closes are planned for Showcase.

API

Options

title

The headline, which names the dialog

Typestring
Defaultundefined
subtitle

A line below the headline

Typestring
Defaultundefined
content

The body, as HTML

Typestring
Defaultundefined
buttons

The actions, in order

TypeDialogButton[]
Default[]
size

The width; fullscreen fills the viewport

Type'small' | 'medium' | 'large' | 'fullwidth' | 'fullscreen'
Default'medium'
animation

How it enters and leaves

Type'scale' | 'slide-up' | 'slide-down' | 'fade'
Default'scale'
footerAlignment

Where the actions sit

Type'right' | 'left' | 'center' | 'space-between'
Default'right'
divider

Lines above and below the content

Typeboolean
Defaultfalse
closeButton

A close button in the header

Typeboolean
Defaulttrue at fullscreen, else false
open

Whether it starts open

Typeboolean
Defaultfalse
closeOnOverlayClick

Whether a click on the scrim closes it

Typeboolean
Defaulttrue
closeOnEscape

Whether Escape closes it

Typeboolean
Defaulttrue
layer

Shows it in the top layer, as a native <dialog> with showModal(); without it, it is in an overlay of its own in container

Type'top'
Defaultundefined
container

Where it is mounted

TypeHTMLElement
Defaultdocument.body
modal

false leaves out aria-modal, and the page behind it keeps scrolling; outside the top layer it stays reachable too

Typeboolean
Defaulttrue
autofocus

Focuses it when it opens

Typeboolean
Defaulttrue
trapFocus

Keeps Tab inside it

Typeboolean
Defaulttrue
role

The role, dialog at fullscreen and alertdialog otherwise

Type'alertdialog' | 'dialog'
Defaultby size
ariaLabel

The name without a title

Typestring
Defaultundefined
animationDuration

When afteropen and afterclose follow, in ms

Typenumber
Default500 to open, 150 to close
zIndex

The overlay's z-index, outside the top layer

Typenumber
Defaultundefined
on

Event handlers registered at creation

Type{ [event]: handler }
Defaultundefined
class

Additional CSS classes

Typestring
Defaultundefined

A button

text

The label

Typestring
Defaultrequired
variant

The button's variant

Typestring
Default'text'
onClick

Its action; false keeps the dialog open

Type(event, dialog) => void | boolean
Defaultundefined
closeDialog

Whether it closes the dialog

Typeboolean
Defaulttrue
autofocus

Focuses it when the dialog opens

Typeboolean
Defaultfalse
attributes

More of the button's options

TypeRecord<string, unknown>
Defaultundefined
size

The button's size

Typestring
Defaultundefined

Methods

open() / close() / toggle(open?)

Opens or closes it

Parametersopen?: boolean
ReturnsDialogComponent
isOpen()

Whether it is open

Parametersnone
Returnsboolean
setTitle(title) / getTitle()

The headline

Parameterstitle: string
ReturnsDialogComponent / string
setSubtitle(subtitle) / getSubtitle()

The subtitle

Parameterssubtitle: string
ReturnsDialogComponent / string
setContent(content) / getContent()

The body, as HTML

Parameterscontent: string
ReturnsDialogComponent / string
addButton(button) / removeButton(indexOrText)

Adds or removes an action

Parametersbutton: DialogButton, indexOrText: number | string
ReturnsDialogComponent
getButtons()

The actions

Parametersnone
ReturnsDialogButton[]
setSize(size) / setFooterAlignment(alignment)

The width, where the actions sit

Parameterssize: DialogSize, alignment: DialogFooterAlignment
ReturnsDialogComponent
toggleDivider(show) / hasDivider()

The lines around the content

Parametersshow: boolean
ReturnsDialogComponent / boolean
getHeaderElement() / getContentElement() / getFooterElement()

Its regions

Parametersnone
ReturnsHTMLElement | null
confirm(options)

Replaces the content and actions with a question, opens it, and resolves to the button pressed: true for the confirming one, which comes last, false for the other. Closed any other way (Escape, the scrim, close()), it resolves false. The message is text

Parameters{ message, title?, confirmText?, cancelText?, confirmVariant?, cancelVariant?, size? }
ReturnsPromise<boolean>
on(event, handler) / off(event, handler)

Adds or removes a listener

Parametersevent: string, handler: Function
ReturnsDialogComponent
destroy()

Removes it

Parametersnone
Returnsvoid
element

The dialog

TypeHTMLElement
overlay

The scrim it sits in, outside the top layer

TypeHTMLElement

Events

beforeopen / beforeclose

It is about to open or close; preventDefault() stops it

Payload{ dialog, preventDefault, defaultPrevented }
open / close

Emitted inside open() and close(), once the dialog is open or closed. The animation finishing is afteropen / afterclose

Payload{ dialog }
afteropen / afterclose

Its animation is over

Payload{ dialog }

The web component dispatches open and close, without a detail, and cancel when Escape asks it to close, which preventDefault() refuses.

Styling

.mtrl-dialog, .mtrl-dialog--visible { }
.mtrl-dialog--small, .mtrl-dialog--large, .mtrl-dialog--fullwidth, .mtrl-dialog--fullscreen { }
.mtrl-dialog--slide-up, .mtrl-dialog--slide-down, .mtrl-dialog--fade { }
.mtrl-dialog__overlay { }                 /* the scrim, outside the top layer */
.mtrl-dialog__header, .mtrl-dialog__header-title, .mtrl-dialog__header-subtitle { }
.mtrl-dialog__header-close, .mtrl-dialog__content, .mtrl-dialog__footer { }
.mtrl-dialog__footer--left, .mtrl-dialog__footer--center, .mtrl-dialog__footer--space-between { }
.mtrl-dialog__header-divider, .mtrl-dialog__footer-divider { }

Measurements

Attribute Value
Container surface-container-high, 28dp corners, elevation 3
Width 280dp to 560dp; small 360dp at most
Scrim scrim at 32%
Headline Headline Small, on-surface
Supporting text Body Medium, on-surface-variant
Padding 24dp; 16dp between the headline and the content
Actions 8dp apart
Full screen No corners; 56dp header, Title Large