Modal
BetaFeedback and overlaysOpen in the workshop
A focused task on top of the page: a short form or a decision.
dialog.xg-modal (--sm --lg) > .xg-modal__header (.xg-modal__title + close) + .xg-modal__body + .xg-modal__footer · open with [data-xg-open="id"], close with [data-xg-close]Example and markup
Live, from xg-ui.css and xg-ui.js. Switch the brand and mode on the example itself, or for the whole site in the header.
Markup
<button class="xg-btn" type="button" data-xg-open="dlg-goal">Set a revenue goal</button>
<dialog class="xg-modal" id="dlg-goal" aria-labelledby="dlg-goal-t">
<form method="dialog" style="display:contents">
<div class="xg-modal__header">
<h2 class="xg-modal__title" id="dlg-goal-t">Set a revenue goal</h2>
<button class="xg-btn xg-btn--ghost xg-btn--icon xg-btn--sm" data-xg-close aria-label="Close">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M18 6 6 18"/>
<path d="m6 6 12 12"/>
</svg>
</button>
</div>
<div class="xg-modal__body">
<p>We pace your demand partners against this target.</p>
<div class="xg-field">
<label class="xg-label" for="goal-amt">Target</label>
<div class="xg-input-group">
<span class="xg-input-group__prefix">$</span>
<input class="xg-input" id="goal-amt" value="250,000">
</div>
</div>
<div class="xg-field">
<label class="xg-label" for="goal-by">By</label>
<select class="xg-select" id="goal-by">
<option>End of quarter</option>
<option>End of month</option>
</select>
</div>
</div>
<div class="xg-modal__footer">
<button class="xg-btn xg-btn--secondary" value="cancel" data-xg-close>Cancel</button>
<button class="xg-btn" value="ok">Set goal</button>
</div>
</form>
</dialog>Variants
Rename campaign
Markup
<div class="xg-modal xg-modal--static" role="dialog" aria-labelledby="sm-t">
<div class="xg-modal__header">
<h2 class="xg-modal__title" id="sm-t">Rename campaign</h2>
<button class="xg-btn xg-btn--ghost xg-btn--icon xg-btn--sm" type="button" aria-label="Close">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M18 6 6 18"/>
<path d="m6 6 12 12"/>
</svg>
</button>
</div>
<div class="xg-modal__body">
<div class="xg-field">
<label class="xg-label" for="rn">Name</label>
<input class="xg-input" id="rn" value="Holiday promo — CTV">
</div>
</div>
<div class="xg-modal__footer">
<button class="xg-btn xg-btn--secondary" type="button">Cancel</button>
<button class="xg-btn" type="button">Rename</button>
</div>
</div>When to use it
Use it for
short tasks that must finish before going on: rename, set a goal, invite a user.
Not for
long forms (a page); information that should stay visible (Drawer); confirmations (Alert dialog).
Rules
- Title is the task (“Set a revenue goal”); the primary button repeats its verb (“Set goal”).
- Escape, the close button and the backdrop all cancel; unsaved input asks before closing.
- No modal on top of a modal.
Accessibility
- Native <dialog> with showModal(): focus is trapped, the page is inert, Escape closes, focus returns to the opener. aria-labelledby points at the title.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Feedback and overlays: Alert dialog, Drawer, Toast, Alert, Popover. Used in the patterns Forms and overlays.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).