2.17.0
Modals gather information, complete a subtask, or provide additional information without losing the context of an underlying page.
Use when displaying information that does not require a user action, such as a read-only document or a supplemental video.
I am a dismissible modal that displays non-essential information.
I am a dismissible modal that displays non-essential information.
I am a dismissible modal that displays non-essential information.
<div class="mds-modal">
<div class="mds-modal__wrapper">
<section role="dialog" aria-labelledby="title---83487" class="mds-modal__container" aria-hidden="true">
<div class="mds-modal__inner">
<header class="mds-modal__header">
<div class="mds-modal__actions">
<button class="mds-button mds-button--icon-only" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left">
<use xlink:href="/icons/mds.svg#question-circle">
<title>Help</title>
</use>
</svg>
</button>
<button class="mds-button mds-button--icon-only" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left">
<use xlink:href="/icons/mds.svg#print">
<title>Print</title>
</use>
</svg>
</button>
<button class="mds-button mds-button--icon-only" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left">
<use xlink:href="/icons/mds.svg#remove">
<title>Close</title>
</use>
</svg>
</button>
</div>
<h1 class="mds-modal__title" id="title---83487">
Dismissible Modal
</h1>
</header>
<div class="mds-modal__content">
<p>I am a dismissible modal that displays non-essential information.</p>
</div>
</div>
</section>
</div>
</div>
<mds-modal title="Dismissible Modal">
<p>I am a dismissible modal that displays non-essential information.</p>
<span slot="mds-modal-actions">
<mds-button variation="icon-only" icon="question-circle">Help</mds-button>
<mds-button variation="icon-only" icon="print">Print</mds-button>
<mds-button variation="icon-only" icon="remove">Close</mds-button>
</span>
</mds-modal>
escape
, or clicking outside the modal.I am a modal that displays non-essential information and has no title.
I am a modal that displays non-essential information and has no title.
I am a modal that displays non-essential information and has no title.
<div class="mds-modal">
<div class="mds-modal__wrapper">
<section role="dialog" aria-labelledby="title---98192" class="mds-modal__container" aria-hidden="true">
<div class="mds-modal__inner">
<header class="mds-modal__header mds-modal__header--no-title">
<div class="mds-modal__actions">
<button class="mds-button mds-button--icon-only" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left">
<use xlink:href="/icons/mds.svg#question-circle">
<title>Help</title>
</use>
</svg>
</button>
<button class="mds-button mds-button--icon-only" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left">
<use xlink:href="/icons/mds.svg#print">
<title>Print</title>
</use>
</svg>
</button>
<button class="mds-button mds-button--icon-only" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left">
<use xlink:href="/icons/mds.svg#remove">
<title>Close</title>
</use>
</svg>
</button>
</div>
<h1 class="mds-modal__title" id="title---98192">
Dismissible Modal
</h1>
</header>
<div class="mds-modal__content">
<p>I am a modal that displays non-essential information and has no title.</p>
</div>
</div>
</section>
</div>
</div>
<mds-modal title="Dismissible Modal" title-hidden>
<p>I am a modal that displays non-essential information and has no title.</p>
<span slot="mds-modal-actions">
<mds-button variation="icon-only" icon="question-circle">Help</mds-button>
<mds-button variation="icon-only" icon="print">Print</mds-button>
<mds-button variation="icon-only" icon="remove">Close</mds-button>
</span>
</mds-modal>
escape
, or clicking outside the modal.Use when a task must be completed, such as entering data and then saving or confirming.
The user can’t close this modal by clicking outside of it. The user must select one of the button options inside the modal header to close it.
The user can’t close this modal by clicking outside of it. The user must select one of the button options inside the modal header to close it.
The user can’t close this modal by clicking outside of it. The user must select one of the button options inside the modal header to close it.
<div class="mds-modal">
<div class="mds-modal__wrapper">
<section role="dialog" aria-labelledby="title---28542" class="mds-modal__container" aria-hidden="true">
<div class="mds-modal__inner">
<header class="mds-modal__header">
<div class="mds-modal__actions">
<button class="mds-button mds-button--icon-only" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left">
<use xlink:href="/icons/mds.svg#question-circle">
<title>Help</title>
</use>
</svg>
</button>
<button class="mds-button mds-button--icon-only" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left">
<use xlink:href="/icons/mds.svg#print">
<title>Print</title>
</use>
</svg>
</button>
<button class="mds-button " type="button" data-mds-modal-close>
Cancel
</button>
<button class="mds-button mds-button--primary" type="button">
Save
</button>
</div>
<h1 class="mds-modal__title" id="title---28542">
Action Required Modal
</h1>
</header>
<div class="mds-modal__content">
<p>The user can’t close this modal by clicking outside of it. The user must select one of the button options inside the modal header to close it.</p>
</div>
</div>
</section>
</div>
</div>
<mds-modal title="Action Required Modal" action-required>
<p>The user can’t close this modal by clicking outside of it. The user must select one of the button options inside the modal header to close it.</p>
<span slot="mds-modal-actions">
<mds-button variation="icon-only" icon="question-circle">Help</mds-button>
<mds-button variation="icon-only" icon="print">Print</mds-button>
<mds-button variation="secondary">Cancel</mds-button>
<mds-button variation="primary">Save</mds-button>
</span>
</mds-modal>
escape
or clicking outside the modal.Modals are available at a single size, which uses a bold level 5 heading (20px) for the title text and medium Buttons.
Modals are available in three predefined widths: 600px, 900px (default), and 1200px. Width can be configured using modifier classes or props.
I am a 600px wide modal.
I am a 900px wide modal.
I am a 1200px wide modal.
max-width
and a width: 90%
rule, ensuring modals are responsive on narrow viewports.Predefined widths are a starting point. If requirements call for a different modal width, work with a designer to create custom width styles in your product’s CSS.
[.my-custom-modal-width] .mds-modal__container {
max-width: 1000px;
}
<!-- HTML -->
<div class="mds-modal [my-custom-modal-width] mds-modal--open mds-modal--active"> ... </div>
<!-- Web Component -->
<mds-modal class="[my-custom-modal-width]"> ... </mds-modal>
Modals consist of three elements:
z-index
value when you compose this component with other layered components (e.g., Dialogs, Tooltips, Popovers or Notifications) to meet your product requirements. escape
or clicking outside of the modal.escape
keyUse title case for titles. (This means capitalize prepositions and conjunctions of four or more letters and all primary words.)
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
Renders a 600px wide modal. |
|
|
Renders a 900px wide modal. |
|
|
Renders a 1200px wide modal. |
|
|
Invokes overlay and triggers visibility of modal. |
|
|
Starts animation of the modal. |
|
|
Opacity increased to |
|
|
Removes header borders and margins. |
When setting props as attributes on a custom HTML element, use kebab-case
instead of camelCase
.
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
String |
|
— |
A space-separated list of element |
|
String |
|
— |
The |
|
Boolean |
— |
— |
If |
|
String |
Required |
— |
Sets the title text. |
|
Boolean |
— |
|
If |
|
Boolean |
— |
|
Sets the visibility of the modal. |
|
String |
One of: |
|
Alters the width of the modal. |
Pass content in between the <mds-modal></mds-modal>
tags to set the modal’s content.
Slot Name
|
Description
|
---|---|
|
Displays actions, usually Buttons, on the right side of the modal. |
Method Name
|
Description
|
---|---|
|
Opens the modal. |
|
Dismisses the modal. |
Event Name
|
Description
|
---|---|
|
Triggers when the modal is dismissed. |
|
Triggers when the modal is initially launched. |
|
Triggers when the modal is opened. |
Setting title
, id
, actions
, and actionRequired
via props. Using the default slot for modal content:
<mds-modal id="my-modal" title="My Modal Title" width="1200px" action-required>
[Modal Content]
<span slot="mds-modal-actions">
<mds-button variation="secondary">Cancel</mds-button>
<mds-button variation="primary">Save</mds-button>
</span>
</mds-modal>
dialog
role, ensuring screen readers properly announce the element.aria-labelledby
attribute on the <section>
element to reference the id
assigned to the Modal’s title to provide screen readers with accessible text used to describe a modal’s purpose.aria-describedby
attribute to the <section>
element and reference the id
of a body of text that further describes the modal’s purpose.aria-hidden="true"
to the modal’s <section>
element to prevent it from being read by a screen reader. When the modal becomes visible, update this attribute to false
, allowing a screen reader to access its content.