Style all elements with an invalid value with CSS

CSSWeb DevelopmentFront End Technology

To style all <input> elements with an invalid value, use the CSS :invalid selector.


You can try to run the following code to implement the :invalid selector −

Live Demo

<!DOCTYPE html>
         input:invalid {
            background: red;
      <input type = "email" value = "InvalidEmail">
      <p>The style (red color background) appears if you type an irrelevant/ invalid email address.</p>
Updated on 30-Jun-2020 11:13:45