2.16.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-modal-1" 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-modal-1"> 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" id="modal-1" 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>">
<p>I am a dismissible modal that displays non-essential information.</p>
</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 dismissible modal that displays non-essential information.
<div class="mds-modal">
<div class="mds-modal__wrapper">
<section role="dialog" aria-labelledby="title-modal-2" 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-modal-2"> 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 id="modal-2" 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>">
<p>I am a dismissible modal that displays non-essential information.</p>
</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-modal-3" 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-modal-3"> 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 id="modal-3" 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>">
<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>
</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. |
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
|
— |
An element |
|
String |
|
— |
The |
|
Boolean |
— |
— |
If |
|
String |
— |
|
Markup for actions in the modal’s header. |
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
String |
Required |
— |
Content for the modal, can also be passed using the default slot. |
|
String |
Required |
— |
The |
|
String |
Required |
— |
Sets the title text. |
|
Boolean |
— |
|
If |
|
Boolean |
— |
|
Sets visibility of the modal. |
|
String |
Enum: |
|
Alters the modal’s width. |
actionRequired
would be written as action-required
.Any content passed in between the <mds-modal></mds-modal>
tags will be used as the modal’s content
.
Method Name
|
Description
|
---|---|
|
Opens the modal. |
|
Dismisses the modal. |
Event Name
|
Description
|
---|---|
|
This event is triggered after the modal is dismissed. |
|
This event is triggered after the modal is initially launched. |
|
This event is triggered after the modal is launched and opened. |
Setting title
, id
, actions
, and action-required
via props, using the default slot for modal content:
<mds-modal id="my-modal" title="My Modal Title" width="1200px" action-required actions="<mds-button variation='secondary'> Cancel </mds-button> <mds-button variation='primary'> Save </mds-button>"> [Modal Content] </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.