CSS :invalid Pseudo Class

The CSS :invalid pseudo-class selects <form> elements with a value that is invalid according to the element's settings.

The :invalid selector only works for form <input> elements with min and max attributes, email fields without a legal email, number fields without a numeric value or required fields with empty value .

Version

CSS3

Syntax

:invalid {
css declarations;
}

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      input:invalid {
      border: 2px solid #ff0000;
      }
    </style>
  </head>
  <body>
    <h2>:invalid selector example</h2>
    <form>
      <input type="email" value="E-mail">
    </form>
  </body>
</html>

Browser support

10.0+ 12.0+ 4.0+ 10.1+ 10.0+

Practice Your Knowledge

The :invalid selector doesn't work for




Related articles