Tailwind have multiple utilities for different inputs states like required, invalid, and disabled. See the pseudo-class reference for a complete list of available pseudo-class modifiers.
But what if user just loaded website and there are required inputs with default (empty) value? They will be immediately red and invalid - that’s not what you expect!
You should wait with input validation to user. That’s why the CSS pseud-class:user-invalid exists. This class represents any validated form element whose value isn’t valid based on their validation constraints, after the user has interacted with it. Right now :user-invalid pseudo-class isn’t very well
supported - works only in Firefox.
Let’s crate following Javascript (sort of polyfill):
This code adds a dirty class to all changed input fields, which helps us to simulate the :user-invalid pseudo-class and clearly mark all inputs that have been changed by the user. Then you can easily distinguish between changed and unchanged inputs that are invalid.
Following Tailwind code requires tailwindcss-forms plugin: