--- title: Modal description: >- The modal component displays content in an overlay. Use to create a distraction-free experience such as a confirmation dialog or a settings panel. api_name: app-home source_url: html: 'https://shopify.dev/docs/api/app-home/web-components/overlays/modal' md: 'https://shopify.dev/docs/api/app-home/web-components/overlays/modal.md' --- # Modal The modal component displays content in an overlay. Use to create a distraction-free experience such as a confirmation dialog or a settings panel. A button triggers the modal using the `commandFor` attribute. Content within the modal scrolls if it exceeds available height. #### Use cases * **Confirmation dialogs:** Display confirmation prompts for destructive or irreversible actions like deleting resources. * **Settings panels:** Present focused settings or configuration forms in a distraction-free overlay. * **Data entry:** Collect structured input through forms displayed in a modal with save and cancel actions. * **Detail previews:** Show detailed information or previews without navigating away from the current page. *** ## Properties Configure the following properties on the modal component. * **accessibilityLabel** **string** **required** A label that describes the purpose of the modal. When set, it will be announced to users using assistive technologies and will provide them with more context. This overrides the `heading` prop for screen readers. * **heading** **string** **required** A title that describes the content of the modal. * **padding** **"base" | "none"** **Default: 'base'** **required** Adjust the padding around the modal content. `base`: applies padding that is appropriate for the element. `none`: removes all padding from the element. This can be useful when elements inside the modal need to span to the edge of the modal. For example, a full-width image. In this case, rely on box with a padding of 'base' to bring back the desired padding for the rest of the content. * **size** **"small" | "small-100" | "base" | "large" | "large-100"** **Default: 'base'** **required** The size of the modal component, controlling its width and height. Larger sizes provide more space for content while smaller sizes are more compact. * **showOverlay** **() => void** **required** A method to programmatically show the overlay. * **hideOverlay** **() => void** **required** A method to programmatically hide the overlay. * **toggleOverlay** **() => void** **required** A method to programmatically toggle the visibility of the overlay. ### Events The modal component provides event callbacks for handling user interactions. Learn more about [handling events](https://shopify.dev/docs/api/polaris/using-polaris-web-components#handling-events). * **afterhide** **CallbackEventListener\ | null** **required** A callback fired after the modal is hidden. * **aftershow** **CallbackEventListener\ | null** **required** A callback fired after the modal is shown. * **hide** **CallbackEventListener\ | null** **required** A callback fired when the modal is hidden. * **show** **CallbackEventListener\ | null** **required** A callback fired when the modal is shown. ### CallbackEventListener A function that handles events from UI components. This type represents an event listener callback that receives a \`CallbackEvent\` with a strongly-typed \`currentTarget\`. Use this for component event handlers like \`click\`, \`focus\`, \`blur\`, and other DOM events. ```ts (EventListener & { (event: CallbackEvent): void; }) | null ``` ### CallbackEvent An event object with a strongly-typed \`currentTarget\` property that references the specific HTML element that triggered the event. This type extends the standard DOM \`Event\` interface and ensures type safety when accessing the element that fired the event. ```ts Event & { currentTarget: HTMLElementTagNameMap[T]; } ``` ### Slots The modal component supports slots for additional content placement within the component. Learn more about [using slots](https://shopify.dev/docs/api/polaris/using-polaris-web-components#slots). * **children** **HTMLElement** The content displayed within the modal component, typically including form fields, information, or interactive elements. * **primary-action** **HTMLElement** The main action button displayed in the modal footer, representing the primary action users should take. Only accepts a single button component with a `variant` of `primary`. This action should align with the modal's main purpose. * **secondary-actions** **HTMLElement** Additional action buttons displayed in the modal footer, providing alternative or supporting actions. Only accepts button components with a `variant` of `secondary` or `auto`. These are visually de-emphasized to establish clear hierarchy. *** ## Examples ### Confirm a merchant action Focus merchant attention on a critical decision before proceeding. This example presents a delete confirmation with cancel and confirm buttons. ## html ```html Open Displaying more details here. Close Save ``` ### Show information in a modal Present information that needs merchant acknowledgment. This example displays a simple announcement with a heading and body text. ## html ```html Show product info This product is currently out of stock and cannot be ordered. Close ``` ### Confirm an action with buttons Provide clear choices with action buttons in the modal footer. This example pairs primary and secondary buttons for confirming or canceling. ## html ```html Delete product Are you sure you want to delete "Winter jacket"? This action cannot be undone. Delete product Cancel ``` ### Collect input with a form Gather information without leaving the current context. This example embeds a feedback form with text inputs and a submit button. ## html ```html Edit customer Retail Wholesale VIP Save changes Cancel ``` ### Choose modal size Adjust modal width to match your content needs. This example demonstrates small, base, and large size variations. ## html ```html Small modal Large modal Are you sure you want to proceed? Confirm Cancel Order #1001 Placed on March 15, 2024 Items Winter jacket - $89.99 Wool scarf - $29.99 Leather gloves - $45.99 Total: $165.97 Close ``` ### Display full-width content Display media or tables that need full-width space. This example sets the `padding` property to false for edge-to-edge content. ## html ```html View product image Image would display here with full width Close ``` ### Delete with async handling Safely handle destructive operations with proper feedback. This example implements loading states, error handling, and async confirmation. ## html ```html Delete product This will permanently delete "Blue T-Shirt". This action cannot be undone. Cancel Delete product ``` *** ## Best practices * Use for focused, specific tasks that require merchants to make a decision or acknowledge critical information. * Include a prominent and clear call to action. * Don't nest modals (avoid launching one modal from another). * Use specific action verbs: Label buttons with clear verbs like "Delete", "Save", or "Continue" rather than vague terms like "Yes", "OK", or "Submit". * For destructive actions, explain the consequences in the modal body. * Use thoughtfully and sparingly—don't create unnecessary interruptions. * Use as a last resort for important decisions, not for contextual tools or actions that could happen on the page directly. *** ## Limitations * Modals can only be opened by user interaction, not programmatically on page load. * The modal always renders centered in the viewport and cannot be repositioned. * Content within the modal scrolls if it exceeds the available height. ***