Inputs
Text field, text area, and dropdown. Every field has a visible label, says required in words, ties its hint and error to the control, and tells people exactly what to fix.
Try it
Leave something out and press Check. Each error says what to do, sits by its field, and focus moves to the first one.
States
Use the email on your invoice.
Error: Enter a phone number, like 555 201 4477.
You can copy it, not change it.
Plans change at renewal.
Code
Plain HTML for any site, or React. Both use the same styles, so the inputs looks the same wherever it lands.
ReadyAny website, Shopify, WordPress, Square, plain hosting
<link rel="stylesheet" href="tokens.css">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="forms.css">
<!-- Text field: a visible label, required in words, a hint, and autocomplete. -->
<div class="prism-field">
<label class="prism-label" for="email">Email <span class="prism-label__note">(required)</span></label>
<p class="prism-hint" id="email-hint">We only use it to send your receipt.</p>
<input class="prism-input" id="email" name="email" type="email" autocomplete="email" required aria-describedby="email-hint">
</div>
<!-- With an error: aria-invalid, and the message tied to the field. Say what to do. -->
<div class="prism-field">
<label class="prism-label" for="phone">Phone</label>
<p class="prism-error" id="phone-error"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 7.5v5.5M12 16.5v.5" stroke-linecap="round"/></svg><span><span class="prism-visually-hidden">Error: </span>Enter a phone number, like 555 201 4477.</span></p>
<input class="prism-input" id="phone" name="phone" type="tel" autocomplete="tel" aria-invalid="true" aria-describedby="phone-error">
</div>
<!-- Text area. -->
<div class="prism-field">
<label class="prism-label" for="about">About your project</label>
<textarea class="prism-input" id="about" name="about" rows="4"></textarea>
</div>
<!-- Dropdown: the native select, so phones show their own picker. -->
<div class="prism-field">
<label class="prism-label" for="budget">Budget</label>
<select class="prism-input" id="budget" name="budget">
<option value="">Choose one</option>
<option>Under $5,000</option>
<option>$5,000 to $15,000</option>
<option>Over $15,000</option>
</select>
</div>
<!-- Read only: can be read and copied. Disabled: not in use right now. -->
<input class="prism-input" value="ORDER-20481" readonly aria-label="Order number">Accessibility
- Every field has a visible label that stays when someone types. A placeholder is only an example.
- Required is written in words in the label, not only shown with a star.
- Hints and errors are tied to the field, so screen readers read them when the field gets focus.
- Errors show an icon, a word, and a thicker edge, never red alone, and say what to do next.
- After a failed check, focus moves to the first field that needs fixing.
- Text is 16 pixels, so phones do not zoom in, and every control is at least 44 pixels tall.
- Email, phone, and name fields carry autocomplete, so browsers and password managers can fill them.
- The dropdown is the browser's own, so phones show their own picker and every keyboard works.