Loading...
input:invalid {
border-color: red;
}input:user-invalid {
border-color: red;
}:user-invalid waits until the user interacts or submits, so empty required fields aren't red on load.
:invalid, which marks empty required fields red before the user types.:user-invalid instead of :invalid, so required fields aren't red on page load.:invalid matches as soon as the value breaks a constraint, even on load. :user-invalid matches only after the user has interacted with the field or tried to submit.
Place the message after the input and reveal it with a sibling selector, like input:user-invalid + .error, and link it with aria-describedby.