Style invalid fields with :invalid, and a required field can show up red before the visitor has typed a single letter. Not a friendly welcome. There is a better pseudo-class.
input:user-invalid {
border: 2px solid red;
}
:user-invalid matches a form field that is invalid after the user has interacted with it. So the field turns red once someone typed a bad email address and moved on, or tried to submit, and not on page load.
It works with the validation you already have in the HTML: required, type="email", min and max, pattern. No JavaScript needed for the basic case.
<label>Email <input type="email" required></label>
Add a message next to it with a sibling selector, for example input:user-invalid + .hint { display: block; }, and you have friendly form errors in plain CSS.
MDN describes the exact rule as a bit more subtle: the field must match :invalid, :out-of-range or be an empty required field, between a submit attempt and the next interaction. In practice that means it appears when the visitor has done something, which is what you want.
Caveats. MDN marks it widely available since November 2023, so very old browsers simply show no error styling. That is fine as long as the form still validates on submit. And never rely on client-side validation alone; the server has to check everything again.
Further reading: MDN: :user-invalid