How can you target an input element in CSS based on its validation state?

  • input:disabled { }
  • input:invalid { }
  • input:required { }
  • input:valid { }
To target an input element in CSS based on its validation state, you can use the :invalid pseudo-class. This selector matches input elements that have failed validation, such as a required field left blank or an email input with an invalid format. For example, input:invalid { border: 2px solid red; } can be used to style invalid input elements.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *