Style all <input> elements with a valid value with CSS

CSSWeb DevelopmentFront End Technology

Use the CSS : valid selector to style all <input> elements with a valid value .

Example

You can try to run the following code to implement the :valid Selector:

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         input:valid {
            background: red;
            color: white;
         }
      </style>
   </head>
   <body>
      <h2>Heading</h2>
      <input type = "email" value = "amit@example.com">
      <p>The style (red color background) appears if you type a relevant/ valid email address.</p>
   </body>
</html>

Output

raja
Published on 08-May-2018 10:46:49
Advertisements