Skip to content
IndexRequest a UIAboutContact

Validation States

Inline field validation with clear error, success and helper text states.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a password field with inline validation. Rules: at least 8 characters, contains a number. Validate on blur; once an error has been shown, re-validate on every input. States: neutral, valid (accent border and a check icon on the right), invalid (red border #ff6b6b, alert icon on the right, message below). The message is an element with id referenced by aria-describedby, role="alert" when shown, and explains the first failing rule ("Use at least 8 characters" or "Add at least one number"). Set aria-invalid appropriately. When the field becomes invalid play a 300ms three-cycle shake of 4px; the message fades and slides in over 180ms. Include a helper line when neutral ("8+ characters and a number"). A submit button is disabled until the field is valid. Skip shake and slide under prefers-reduced-motion.

About this pattern

Definition

The visual and textual feedback a form field gives about its value: neutral, valid, or invalid with a specific message. Errors are shown next to the field and announced to assistive technology.

Purpose & UX principles

  • Validate after the user leaves the field (on blur), not while they are still typing, then re-check live once an error is shown.
  • Say what is wrong and how to fix it ("Use at least 8 characters"), not just "Invalid".
  • Do not use colour alone: pair it with an icon and text.

Interaction states

  • Neutral, focused, valid (green border, check icon), invalid (red border, alert icon, message), disabled.
  • The input has aria-invalid="true" and aria-describedby pointing at the message; the message is role="alert" when it first appears.

Motion specification

  • Message: height and opacity, 180ms ease-out, with a 4px upward slide.
  • Invalid field: a brief 3-cycle horizontal shake of 4px over 300ms.
  • Reduced motion: no shake, no slide.

Responsive behaviour

  • Messages sit directly below the field and wrap onto multiple lines instead of truncating.
  • Reserve space for the message or animate its height to avoid pushing the layout abruptly.

Code

HTML
<form class="f" onsubmit="return false" novalidate>
  <label for="pw">Password</label>
  <div class="box" id="box"><input id="pw" type="password" autocomplete="new-password" aria-describedby="msg"><span class="ic" id="ic" aria-hidden="true"></span></div>
  <p id="msg" class="msg help">8+ characters and a number.</p>
  <button class="go" id="go" disabled>Create account</button>
</form>

Related patterns

Text Input

↗
Text InputInputs & Forms

Checkbox

↗
CheckboxInputs & Forms

Toast

↗
ToastFeedback & Notifications