Form
Collect fields, validate them, and emit a submission event.
Design examples
Section titled “Design examples”Labels, fields and actions form a small vertical rhythm. Submitting stays inside this preview.
<section class="specimen">
<ds-form><ds-input label="Name" name="name" value="Nia Vale" required></ds-input><ds-input label="Email" name="email" type="email" placeholder="you@example.com" required></ds-input><ds-gap></ds-gap><ds-button primary type="submit">Reserve a place</ds-button></ds-form>
</section>
<style>
.specimen { width: 100%; min-width: 0; --cell: calc(20px * var(--sf, 1)); }
.specimen .line { width: 100%; }
.specimen .grow { flex: 1; min-width: 0; }
.specimen .muted { color: var(--ds-text-color-muted); }
.specimen .mono { --ds-typeface-regular: var(--ds-typeface-mono); font-variant-numeric: tabular-nums; }
.specimen .value { width: calc(4 * var(--cell)); text-align: right; }
.specimen .mark { display: inline-flex; align-items: flex-end; width: var(--cell); height: var(--ds-control-height); flex: 0 0 var(--cell); }
.specimen .columns { display: flex; flex-wrap: wrap; gap: var(--cell); }
.specimen .columns > * { min-width: 0; }
.specimen fieldset { border: 0; padding: 0; margin: 0; }
.specimen legend { padding: 0; }
.specimen label { display: flex; align-items: flex-end; gap: calc(var(--cell) / 2); min-height: var(--cell); }
.specimen ds-panel { height: calc(10 * var(--cell)); }
</style> A compact single-purpose form with a query and one action.
<section class="specimen">
<ds-form><ds-input label="Search recordings" name="query" value="rain"></ds-input><ds-gap size="05"></ds-gap><ds-button primary type="submit"><span class="mark"><ds-icon type="search" size="large" aria-hidden="true"></ds-icon></span>Search</ds-button></ds-form>
</section>
<style>
.specimen { width: 100%; min-width: 0; --cell: calc(20px * var(--sf, 1)); }
.specimen .line { width: 100%; }
.specimen .grow { flex: 1; min-width: 0; }
.specimen .muted { color: var(--ds-text-color-muted); }
.specimen .mono { --ds-typeface-regular: var(--ds-typeface-mono); font-variant-numeric: tabular-nums; }
.specimen .value { width: calc(4 * var(--cell)); text-align: right; }
.specimen .mark { display: inline-flex; align-items: flex-end; width: var(--cell); height: var(--ds-control-height); flex: 0 0 var(--cell); }
.specimen .columns { display: flex; flex-wrap: wrap; gap: var(--cell); }
.specimen .columns > * { min-width: 0; }
.specimen fieldset { border: 0; padding: 0; margin: 0; }
.specimen legend { padding: 0; }
.specimen label { display: flex; align-items: flex-end; gap: calc(var(--cell) / 2); min-height: var(--cell); }
.specimen ds-panel { height: calc(10 * var(--cell)); }
</style> Try it
Section titled “Try it”Type a name and submit. The result stays in this preview.
<ds-form>
<ds-input label="Your name" name="name" required></ds-input>
<button type="submit">Try submission</button>
</ds-form> Try it locally
Section titled “Try it locally”The example has no action endpoint. Submit an empty field to see validation, then enter a name to see the form data. It sends no server request.
Use a native <button type="submit"> in the form slot. ds-button does not forward a submit type.
Attributes
Section titled “Attributes”| Attribute | Type | Default | What it does |
|---|---|---|---|
action | string | Empty | Optional server endpoint. |
method | string | post | HTTP method for a server submission. |
name | string | Empty | Form name. |
novalidate | boolean | false | Skips validation. |
autocomplete | string | on | Autocomplete preference. |
Events and methods
Section titled “Events and methods”const form = document.querySelector('ds-form');form.addEventListener('form-submit', (event) => { console.log(event.detail.data);});form-invalid reports validation errors. form-reset, form-response and form-error report reset and server outcomes. Methods are getFormData(), validate(), reset() and submit().