# Input States

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

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: error, helper text, disabled, aria-invalid, design system, validation
- Live preview: https://copy-css.com/snippets/input-states
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```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

```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;
}
```

## Notes

- 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.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
