Tailwind Forms
Preflight strips most browser styling from form controls, so inputs start out plain. That's good news: you can style them precisely with utilities and form-state variants such as focus:, invalid:, disabled:, checked: and placeholder:.
Text inputs
| Concern | Classes |
|---|---|
| Box | block w-full rounded-md border border-gray-300 px-3 py-2 |
| Text | text-sm text-gray-900 placeholder:text-gray-400 |
| Focus | focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200 focus:outline-hidden |
| Disabled | disabled:bg-gray-100 disabled:text-gray-500 |
| Error | border-red-500 or invalid:border-red-500 |
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="max-w-sm space-y-4 p-6">
<div>
<label for="name" class="block text-sm font-medium text-gray-700">Full name</label>
<input id="name" placeholder="Ada Lovelace" class="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 text-sm placeholder:text-gray-400 focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200 focus:outline-hidden">
</div>
<div>
<label for="email" class="block text-sm font-medium text-gray-700">Email</label>
<input id="email" type="email" value="not-an-email" class="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 text-sm invalid:border-red-500 invalid:text-red-600 focus:outline-hidden focus:invalid:ring-2 focus:invalid:ring-red-200">
<p class="mt-1 text-xs text-red-600">Please enter a valid email.</p>
</div>
<input disabled value="Disabled field" class="block w-full rounded-md border border-gray-200 bg-gray-100 px-3 py-2 text-sm text-gray-500">
</body>
</html>Inputs with add-ons
Wrap the input and its decoration in a flex container and move the focus style to the wrapper with focus-within::
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="max-w-sm space-y-4 p-6">
<div class="flex rounded-md border border-gray-300 focus-within:border-sky-500 focus-within:ring-2 focus-within:ring-sky-200">
<span class="flex items-center rounded-l-md border-r border-gray-300 bg-gray-50 px-3 text-sm text-gray-500">https://</span>
<input placeholder="example.com" class="min-w-0 flex-1 px-3 py-2 text-sm outline-hidden">
</div>
<div class="relative">
<span class="pointer-events-none absolute inset-y-0 left-3 flex items-center text-gray-400">🔍</span>
<input placeholder="Search…" class="w-full rounded-full border border-gray-300 py-2 pr-4 pl-10 text-sm focus:border-sky-500 focus:outline-hidden">
</div>
</body>
</html>pointer-events-none lets clicks on the icon pass through to the input underneath.
Checkboxes, radios, selects and textareas
| Control | Useful classes |
|---|---|
| Checkbox / radio | size-4 accent-indigo-600 (native) or appearance-none + custom styles |
| Select | appearance-none + a background arrow, or keep native with rounded-md border px-3 py-2 |
| Textarea | w-full rounded-md border p-3 field-sizing-content (grows with content, v4) |
| Range | accent-* |
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="grid max-w-md grid-cols-2 gap-4 p-5 text-sm">
<fieldset class="space-y-2">
<legend class="font-medium">Toppings</legend>
<label class="flex items-center gap-2"><input type="checkbox" checked class="size-4 accent-rose-600"> Cheese</label>
<label class="flex items-center gap-2"><input type="checkbox" class="size-4 accent-rose-600"> Olives</label>
<label class="flex items-center gap-2"><input type="radio" name="s" checked class="size-4 accent-rose-600"> Thin crust</label>
</fieldset>
<div class="space-y-2">
<select class="w-full rounded-md border border-gray-300 bg-white px-3 py-2">
<option>Small</option><option>Medium</option><option>Large</option>
</select>
<textarea placeholder="Delivery notes (I grow as you type)" class="field-sizing-content min-h-16 w-full rounded-md border border-gray-300 p-2"></textarea>
</div>
</body>
</html>Selectable cards with has-checked:
The has-* variant styles a parent based on its children. Wrap a hidden radio in a label, and the whole label lights up when its radio is checked:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="p-5">
<p class="mb-2 text-sm font-medium">Choose a plan</p>
<div class="grid grid-cols-3 gap-3 text-sm">
<label class="cursor-pointer rounded-xl border border-gray-300 p-3 has-checked:border-indigo-600 has-checked:bg-indigo-50 has-checked:ring-2 has-checked:ring-indigo-600">
<input type="radio" name="plan" class="sr-only"><p class="font-semibold">Hobby</p><p class="text-gray-500">$0</p>
</label>
<label class="cursor-pointer rounded-xl border border-gray-300 p-3 has-checked:border-indigo-600 has-checked:bg-indigo-50 has-checked:ring-2 has-checked:ring-indigo-600">
<input type="radio" name="plan" checked class="sr-only"><p class="font-semibold">Pro</p><p class="text-gray-500">$12/mo</p>
</label>
<label class="cursor-pointer rounded-xl border border-gray-300 p-3 has-checked:border-indigo-600 has-checked:bg-indigo-50 has-checked:ring-2 has-checked:ring-indigo-600">
<input type="radio" name="plan" class="sr-only"><p class="font-semibold">Team</p><p class="text-gray-500">$49/mo</p>
</label>
</div>
</body>
</html>Validation after the user interacts: user-invalid:
invalid: applies immediately, even before the user has typed — which can feel rude. user-invalid: (CSS :user-invalid) waits until the user has interacted with the field.
<input required type="email" class="border border-gray-300 user-invalid:border-red-500">Note: If you prefer browser-consistent defaults for every control, the official
@tailwindcss/formsplugin resets them to an easy-to-style baseline (see Plugins).
Tip: Always connect labels to inputs with
for/idor by nesting. It makes the click target larger and lets screen readers announce the field.
Test yourself
Which variant styles a wrapper when the input inside it has focus?
focus:focus-within:group-focus:has-focus-visible:
What is the simplest way to colour a native checkbox?
bg-rose-600accent-rose-600text-rose-600fill-rose-600
Why might you prefer user-invalid: over invalid:?
- It works on buttons
- It only shows the error after the user has interacted with the field
- It is required for
type=email - It removes the need for labels