Actions and inputs
Form layout and validation
.kui-form lays out fields in a column, .kui-form__row puts short fields side by side, .kui-form__section groups them under a heading. <kui-form-check> checks the form on submit with the browser’s own rules and fills the error summary.
The form below fails when it is sent empty. Press Send the request: the summary at the top lists each problem as a link, focus moves to it, and each field shows its own message. Fix a field and its message goes away as you type. When everything is right a success message replaces the summary.
Examples
A request that is checked on submit
Fix these to send the request
Request sent
We will answer within two working days.
<kui-form-check success="form-sent">
<div class="kui-error-summary" hidden>
<h4 class="kui-error-summary__title">Fix these to send the request</h4>
<ul></ul>
</div>
<div class="kui-callout kui-callout--ok" id="form-sent" hidden><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#circle-check"></use></svg><div class="kui-callout__body"><p class="kui-callout__title">Request sent</p><p>We will answer within two working days.</p></div></div>
<form class="kui-form" action="#form" novalidate>
<div class="kui-form__section">
<h4>About you</h4>
<div class="kui-form__row">
<div class="kui-field">
<label class="kui-label" for="form-first">First name<span class="kui-required" aria-hidden="true">*</span></label>
<input class="kui-input" id="form-first" name="first" autocomplete="given-name" required>
</div>
<div class="kui-field">
<label class="kui-label" for="form-last">Last name<span class="kui-required" aria-hidden="true">*</span></label>
<input class="kui-input" id="form-last" name="last" autocomplete="family-name" required>
</div>
</div>
<div class="kui-field">
<label class="kui-label" for="form-mail">Email<span class="kui-required" aria-hidden="true">*</span></label>
<input class="kui-input" id="form-mail" name="email" type="email" autocomplete="email" required aria-describedby="form-mail-hint">
<p class="kui-hint" id="form-mail-hint">We send the answer here.</p>
</div>
<div class="kui-field">
<label class="kui-label" for="form-phone">Phone<span class="kui-optional">optional</span></label>
<input class="kui-input" id="form-phone" name="phone" type="tel" autocomplete="tel" pattern="[+0-9 ]{6,20}" data-error="Use digits, spaces and a leading +." placeholder="+381 64 123 45 67">
</div>
</div>
<div class="kui-form__section">
<h4>The request</h4>
<fieldset class="kui-fieldset">
<legend>Topic<span class="kui-required" aria-hidden="true">*</span></legend>
<div class="kui-choices">
<label class="kui-check"><input class="kui-radio" type="radio" name="topic" value="invoice" required data-error="Choose the topic of the request."><span>An invoice or a payment</span></label>
<label class="kui-check"><input class="kui-radio" type="radio" name="topic" value="contract"><span>A contract</span></label>
<label class="kui-check"><input class="kui-radio" type="radio" name="topic" value="other"><span>Something else</span></label>
</div>
</fieldset>
<div class="kui-form__row">
<div class="kui-field">
<label class="kui-label" for="form-date">Answer by<span class="kui-optional">optional</span></label>
<input class="kui-input" id="form-date" name="by" type="date" min="2026-11-30" data-error="Choose a day from 30 November 2026.">
</div>
<div class="kui-field">
<label class="kui-label" for="form-count">Documents attached</label>
<kui-number class="kui-number"><input class="kui-input" id="form-count" name="count" type="number" min="0" max="20" value="0"></kui-number>
</div>
</div>
<div class="kui-field">
<label class="kui-label" for="form-text">What happened<span class="kui-required" aria-hidden="true">*</span></label>
<textarea class="kui-textarea" id="form-text" name="text" rows="4" minlength="20" required data-error="Write at least 20 characters, so we can help." aria-describedby="form-text-hint"></textarea>
<p class="kui-hint" id="form-text-hint">At least 20 characters.</p>
</div>
<div class="kui-field">
<label class="kui-check"><input class="kui-checkbox" type="checkbox" name="consent" required data-error="Agree to the processing of your data to send the request."><span>I agree that my data is processed to answer this request.</span></label>
</div>
</div>
<div class="kui-actions kui-actions--end kui-actions--stack">
<button class="kui-button" type="reset">Clear</button>
<button class="kui-button kui-button--primary" type="submit">Send the request</button>
</div>
</form>
</kui-form-check>
Rows that fold on a phone
A row puts its fields side by side while each has at least 16 rem; on a narrow screen they stack. Use rows for fields that belong together, such as a postcode and a city.
<div class="kui-form kui-form--wide">
<div class="kui-form__row">
<div class="kui-field"><label class="kui-label" for="form-street">Street and number</label><input class="kui-input" id="form-street" autocomplete="street-address" value="Bulevar kralja Aleksandra 73"></div>
<div class="kui-field"><label class="kui-label" for="form-zip">Postcode</label><input class="kui-input" id="form-zip" autocomplete="postal-code" inputmode="numeric" value="11000"></div>
<div class="kui-field"><label class="kui-label" for="form-city">City</label><input class="kui-input" id="form-city" autocomplete="address-level2" value="Beograd"></div>
</div>
</div>
States
The error summary, as it looks after a failed submit
kui-form-check writes this into the summary and moves focus to it. Each link moves focus to its field.
<div class="kui-error-summary" role="region" aria-labelledby="form-s-title">
<h4 class="kui-error-summary__title" id="form-s-title">Fix these to send the request</h4>
<ul>
<li><a href="#form-first">First name: Fill in this field.</a></li>
<li><a href="#form-mail">Email: Enter an email address, such as name@example.com.</a></li>
<li><a href="#form-text">Write at least 20 characters, so we can help.</a></li>
</ul>
</div>
Classes and attributes
.kui-form, --wide- The column of fields, at most 40 rem wide; --wide removes the limit.
.kui-form__row- Fields side by side, each at least 16 rem; they stack when there is no room.
.kui-form__section- A group of fields under a heading (h2, h3 or h4), with a line above.
fieldset.kui-fieldset- A group of radios or checkboxes with a legend.
kui-form-check- Around a form: checks it on submit with required, type, pattern, min, max and minlength.
.kui-error-summary- Hidden at first; filled with a title and one link per problem after a failed submit.
data-error- On a field: its message, a whole sentence, shown under the field and alone in the summary. Without it the kit’s words are used after the field’s name (“Email: Fill in this field.”).
success- On kui-form-check: the id of a hidden element shown when the form passes. The form then stays on the page.
event kui-valid- Fired when the form passes; call preventDefault to stop the submit and send the data yourself.
Keyboard
- Tab
- Moves through the fields in order.
- Enter
- In a text field, submits the form.
- Enter
- On a link of the summary, moves focus to that field.
Accessibility
- The summary is an alert that takes focus after a failed submit, as the GOV.UK pattern does, so a screen reader reads it at once.
- Each wrong field gets aria-invalid="true" and its message joins its aria-describedby, so the message is read with the field.
- A radio group is marked once and its message is placed under the group.
- Messages are checked again as the person types in a field that was wrong, never before the first submit.
- The required asterisk is aria-hidden; the required attribute is what is announced.
Do and do not
Do
- Keep one column for most forms; rows only for fields that belong together.
- Mark the optional fields when most are required, or the required ones when most are optional.
- Write each message as what to do.
Do not
- Do not disable the submit button until the form is valid; let the summary say what is missing.
- Do not clear what the person typed after a failed submit.
- Do not check a field while the person is still typing in it for the first time.