About Modals
Default modals are used in the vast majority of cases. They are as wide as 50% of the viewport, but include a minimum and maximum width to avoid going too narrow or too wide.
Modals always have an equal amount of space at the top and bottom to account for the height of the close button.
Modals grow according to how much content is within, but once the modal full height (including the previously mentioned space on top and bottom), the content area will begin to scroll.
Modals can have a tagline in the header, simply by adding a paragraph after the heading.
By default, the content area of the modal does not have spacing. This allows for content such as Tables to be full-width to the modal. To get spacing when you need it, apply a padding utility (.slds-p-around_medium
).
Accessibility
Modals, by definition, trap focus. This means that if a user presses Tab or Shift+Tab while their keyboard focus is in the modal, their focus should stay in and cycle through the modal's content.
Expected markup
- Modal has
role="dialog"
- When the modal is open, everything behind it has HTML attribute
aria-hidden="true"
- Modal contains an HTML heading with
tabindex="-1"
- Modal has an
aria-labelledby
attribute whose value is the id of the modal's heading - Modal has an optional
aria-describedby
attribute
Expected keyboard interactions
- Esc key closes the modal and moves focus to whatever triggered the modal to open
- Tab key at bottom of modal cycles focus back to first focusable element at top of modal
- Shift+Tab keys at top of modal cycle focus back to last focusable element at bottom of modal
- Enter key submits modal's form data, if applicable
Mobile
On mobile devices, modals will have buttons of increased size to accommodate tapping with a finger instead of the more precise mouse cursor.
Base
Default Modal Structure
<section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" class="slds-modal slds-fade-in-open"> <div class="slds-modal__container"> <header class="slds-modal__header"> <button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" title="Close"> <svg class="slds-button__icon slds-button__icon_large" aria-hidden="true"> <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#close"></use> </svg> <span class="slds-assistive-text">Close</span> </button> <h2 id="modal-heading-01" class="slds-modal__title slds-hyphenate">Modal Header</h2> </header> <div class="slds-modal__content slds-p-around_medium"> <p>Modal content goes here.</p> </div> <footer class="slds-modal__footer"> <button class="slds-button slds-button_neutral">Cancel</button> <button class="slds-button slds-button_brand">Save</button> </footer> </div></section>
Layout
Layout Variations
Modals support various layout configurations:
- Taglines: Additional context in the header
- Headless: Modal without a header section
- Footless: Modal without a footer section
- Directional: Footer buttons aligned left and right for navigation
Sizes
Modal Sizes
Modals come in different sizes to accommodate various content needs:
- Small:
.slds-modal_small
- 480px max width - Medium:
.slds-modal_medium
- 640px max width - Large:
.slds-modal_large
- 90% viewport width - Full:
.slds-modal_full
- Full screen on small devices
Styling Hooks Overview
Key CSS classes for modal customization:
.slds-modal
- Main modal container.slds-modal__container
- Inner modal container.slds-modal__header
- Modal header.slds-modal__content
- Modal content area.slds-modal__footer
- Modal footer.slds-backdrop
- Modal backdrop
Modal Header
This is a default modal. It contains content that is displayed above the main application. The modal traps focus and requires user interaction to close.
You can include any content here such as forms, tables, or other components.