CSS Input States

Default, error and disabled text field states with helper and error text linked via aria-describedby.

  • error
  • helper text
  • disabled
  • aria-invalid
  • design system
  • validation
HTML
<div class="field-states">
  <label>
    Username
    <input type="text" value="mira" aria-describedby="field-states-hint">
    <small id="field-states-hint">Letters and numbers only.</small>
  </label>
  <label>
    Email
    <input type="email" value="mira@" aria-invalid="true" aria-describedby="field-states-error">
    <small id="field-states-error">Enter a full email address.</small>
  </label>
  <label>
    Plan
    <input type="text" value="Free" disabled>
  </label>
</div>
CSS
.field-states {
  display: grid;
  gap: 12px;
  width: 240px;
  font-family: system-ui, sans-serif;
}

.field-states label {
  display: grid;
  gap: 4px;
  color: #27272a;
  font-size: 13px;
  font-weight: 600;
}

.field-states input {
  padding: 8px 11px;
  border: 1.5px solid #d4d4d8;
  border-radius: 8px;
  background: #fff;
  color: #18181b;
  font: 14px system-ui, sans-serif;
}

.field-states input:focus-visible {
  border-color: #2563eb;
  outline: 3px solid rgba(37, 99, 235, 0.2);
  outline-offset: 0;
}

.field-states small {
  color: #71717a;
  font-size: 12px;
  font-weight: 400;
}

.field-states input[aria-invalid="true"] {
  border-color: #dc2626;
}

.field-states input[aria-invalid="true"]:focus-visible {
  outline-color: rgba(220, 38, 38, 0.2);
}

.field-states input[aria-invalid="true"] + small {
  color: #dc2626;
}

.field-states input[aria-invalid="true"] + small::before {
  content: "⚠ ";
}

.field-states input:disabled {
  border-color: #e4e4e7;
  background: #f4f4f5;
  color: #a1a1aa;
  cursor: not-allowed;
}

About this CSS Input States

This CSS Input States is 58 lines of pure CSS (1.0 KB) with no JavaScript and no dependencies. It uses CSS Grid and keyboard focus styles. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #27272a
  • #d4d4d8
  • #fff
  • #18181b
  • #2563eb
  • #71717a
  • #dc2626
  • #e4e4e7
  • #f4f4f5
  • #a1a1aa

How to use this input states

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .field-states class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback