Role of CSS :invalid Selector


Use the CSS :invalid selector to style all <input> elements with an invalid value. You can try to run the following code to implement the :invalid selector

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         input:invalid {
            background: red;
         }
      </style>
   </head>
   <body>
      <h2>Heading</h2>
         <input type = "email" value = "InvalidEmail">
         <p>The style (red color background) appears if you type an irrelevant/ invalid email address.</p>
   </body>
</html>

Updated on: 30-Jun-2020

129 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements