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 .




:invalid {
css declarations;


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

Browser support

10.0+ 12.0+ 4.0+ 10.1+ 10.0+

Practice Your Knowledge

The :invalid selector doesn't work for

Related articles