Form layout
BetaFormsOpen in the workshop
How fields, sections and actions sit together in a settings page or a dialog.
.xg-stack of .xg-field · two-column grid at 640 px and up · actions in .xg-card__footerExample 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
<form class="xg-card" style="max-width:560px" onsubmit="return false">
<div class="xg-card__header">
<h3 class="xg-card__title">Payout settings</h3>
</div>
<div class="xg-stack">
<div class="xg-field">
<label class="xg-label" for="pay-name">Legal entity name</label>
<input class="xg-input" id="pay-name" value="Example Media Ltd">
</div>
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px">
<div class="xg-field">
<label class="xg-label" for="pay-cur">Currency</label>
<select class="xg-select" id="pay-cur">
<option>USD — US dollar</option>
<option>EUR — Euro</option>
</select>
</div>
<div class="xg-field">
<label class="xg-label" for="pay-min">Minimum payout</label>
<div class="xg-input-group">
<span class="xg-input-group__prefix">$</span>
<input class="xg-input" id="pay-min" value="2,500">
</div>
</div>
</div>
<label class="xg-check">
<input type="checkbox" checked>Email me when a payout is sent</label>
</div>
<div class="xg-card__footer">
<button class="xg-btn xg-btn--secondary" type="button">Cancel</button>
<button class="xg-btn" type="submit">Save settings</button>
</div>
</form>When to use it
Use it for
creating or editing an object: a campaign, a demand partner, payout settings.
Not for
filters above a table (filter bar).
Rules
- One column by default; two columns only for short, related fields (City / Postal code).
- Group into sections with a heading when there are more than seven fields.
- Required fields are the norm; mark the optional ones with “optional”.
- Primary action bottom right; on long forms also keep it visible in a sticky footer.
Accessibility
- Errors summarized at the top after a failed submit, each linking to its field; focus moves to the summary.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Forms: Input, Textarea, Select, Checkbox, Radio, Switch, Segmented control, Search field, Date-range picker.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).