# Confirm Modals

Use a confirm modal to ask users to respond before they continue. The confirm modal is displayed as a dialog on top of the page content using an overlay.

To display a confirm modal in Lightning Experience, import `LightningConfirm` from the `lightning/confirm` module, and call `LightningConfirm.open()` with your desired attributes.

`LightningConfirm` is an alternative to the native `window.confirm()` function, which isn’t supported for cross-origin iframes in Chrome and Safari. Unlike the native confirm function, `LightningConfirm.open()` doesn't halt execution on the page, it returns a promise. Use `async`/`await` or `.then()` for any code you want to execute after the confirm modal is closed.

![A headerless confirm modal over a darkened org.](https://a.sfdcstatic.com/developer-website/sfdocs/lwc/media/dialog_confirm_example.png "A headerless confirm modal")

This example component creates a button that opens the confirm modal that you see in the screenshot.

```html
<!-- c/myApp.html -->
<template>
  <lightning-button 
      onclick={handleConfirmClick} 
      label="Open Confirm Modal">
  </lightning-button>
</template>
```

Import `LightningConfirm` from `lightning/confirm` in the JavaScript file of the component that opens the confirm modal. Create and dispatch a `LightningConfirm` event with `message`, `variant`, and `label` attributes. The `.open()` function returns a promise that resolves to `true` when you click **OK** and `false` when you click **Cancel**.

```javascript
// c/myApp.js
import { LightningElement } from "lwc";
import LightningConfirm from "lightning/confirm";

export default class MyApp extends LightningElement {
  async handleConfirmClick() {
    const result = await LightningConfirm.open({
      message: "This is the confirmation message.",
      variant: "headerless",
      label: "This is the aria-label value",
      // label value isn't visible in the headerless variant
    });
    // confirm window has been closed
  }
}
```

:::tip
The [lwc-recipes](https://github.com/trailheadapps/lwc-recipes) repo has a [miscNotificationModules](https://github.com/trailheadapps/lwc-recipes/tree/main/force-app/main/default/lwc/miscNotificationModules) component that demonstrates confirm modals.
:::

For information about the attributes for `LightningConfirm`, see the \[Component Reference]\(<https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-confirm?type=Specifications>.

**See Also**

- [Component Reference: `lightning/confirm`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-confirm)
