Table of Contents & Menu
On this page
Navigation

Styling inputs depending on state

Tailwind CSS offers variants for styling input fields based on their state, directly mapping to standard CSS pseudo-classes:

JIT Only

These variants are supported only by the Tailwind JIT compiler.
They will not work in a bundle produced by npm run build-dev.

  • invalid:
  • valid:
  • in-range:
  • out-of-range:
  • required:
  • placeholder-shown:
  • indeterminate:

Example

<select id="amount"
        name="amount"
        class="form-select invalid:ring-2 invalid:ring-red-500"
        form="my_form"
        required
>
    <option value="">
        <?= $escaper->escapeHtml(__('Choose an Amount...')) ?>
    </option>
</select>

To prevent invalid styles from applying to empty elements, JavaScript is required.