← All posts

CSS: clean, accessible forms without a library using accent-color, appearance and :user-invalid

Brand-coloured checkboxes, consistent select boxes and error messages that appear at the right moment: native CSS now handles most form styling, no JavaScript required.

CSS: clean, accessible forms without a library using accent-color, appearance and :user-invalid

Key points

  • accent-color brands native checkboxes and radio buttons in one line.
  • :user-invalid waits for interaction before flagging an error, unlike :invalid.
  • Inputs smaller than 16px make iPhones zoom in on focus.

Forms tend to be the least polished part of a website, even though that is where quote requests, sign-ups and payments happen. For years, styling a checkbox or a select meant hiding it and rebuilding it in JavaScript, usually breaking accessibility along the way. Today a handful of native CSS properties covers what most of our projects need.

A sound baseline

Form controls do not inherit the page font, which is why you see Arial forms on otherwise carefully designed sites. Fix that first, then bring in the brand colour:

:root {
  accent-color: #2f5bea; /* checkboxes, radios, range, progress */
}

input, select, textarea, button {
  font: inherit;            /* form controls do not inherit by default */
  font-size: max(1rem, 16px); /* below 16px, iOS Safari zooms on focus */
}

:focus-visible {
  outline: 2px solid #2f5bea;
  outline-offset: 2px;
}

accent-color keeps the native controls, so keyboard use, screen readers and dark mode still work. Pick a colour with enough contrast: the browser adjusts the tick mark, not your choice of hue.

The issue we find most often in audits is 14px inputs. On iPhone, Safari zooms in on every focus and users have to pinch out afterwards. A 16px minimum fixes it without disabling page zoom, which would be an accessibility failure.

A consistent select box

appearance: none removes the operating system’s styling while keeping a real <select>. You then draw your own arrow, here as an inline SVG:

select {
  appearance: none;
  padding: .6em 2.4em .6em .8em;
  border: 1px solid #b8bfcc;
  border-radius: 6px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23555' stroke-width='2'/%3E%3C/svg%3E") no-repeat right .8em center / 12px;
}

Only the closed control is styled; the option list stays native, which is what you want on mobile. If the design calls for a fully custom dropdown, check browser support before you commit.

Showing errors at the right time

With :invalid, an empty required field turns red as soon as the page loads, before the visitor has typed anything. :user-invalid only matches once they have interacted with the field or tried to submit. Current browsers support it.

<label for="email">E-mail</label>
<input id="email" type="email" required aria-describedby="email-error">
<p class="field-error" id="email-error">Please enter a valid e-mail address.</p>
.field-error { display: none; color: #b42318; font-size: .875rem; }

input:user-invalid,
textarea:user-invalid {
  border-color: #b42318;
}

input:user-invalid + .field-error,
textarea:user-invalid + .field-error {
  display: block;
}

Never rely on colour alone. The text message, linked through aria-describedby, is essential, and so is server-side validation: CSS only improves the experience.

FAQ

Do I still need a form library?

For a contact or quote form, rarely. It earns its place in multi-step forms where rules depend on other fields.

How do I apply this in WordPress?

Put these rules in the theme stylesheet. Form plugins add their own classes, so target them in a dedicated file to stay in control of the cascade.

Contact or quote forms that don’t convert? We redesign them to be clear, accessible and pleasant on mobile.

Share LinkedIn Facebook X WhatsApp
</>

webtestudio

Web agency: custom WordPress sites, premium themes and SaaS software.

Discuss your project →