Valid and Invalid Form Input with :valid and :invalid Pseudo-Classes in CSS


Valid & Invalid

Source Code :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Input pseudo-classes</title>
    <style>
      input {
        outline: none;
        border-radius: 3px;
      }
      input:invalid {
        border-color: red;
      }
      input:valid {
        border-color: green;
      }
    </style>
  </head>
  <body>
    <h3>Input pseudo-classes</h3>
    <p>:valid & :invalid</p>
    <form>
      <input type="email" placeholder="Enter Your Email" value="" />
    </form>
  </body>
</html>

Live Preview


CSS Tutorial


Properties Reference


Cascading Style Sheet


Flexbox Tutorial


CSS Grid Tutorial


Transitions Properties


CSS Properties with Examples


CSS Selectors


CSS Pseudo Elements


CSS Attribute Selectors


Input Pseudo Classes


CSS Examples


CSS Animation Projects