CSS :valid Pseudo Class

The :valid pseudo-class selects <form> elements with a value that validates according to the element's settings.

The :valid selector only works for form <input> elements with min and max attributes, email fields with a legal email, number fields with a numeric value or required fields with not empty value.


HTML Living Standard


Selectors Level 4


:valid {
  css declarations;

Example of the :valid selector:

<!DOCTYPE html>
    <title>Title of the document</title>
      input {
        border: 1px solid #cccccc;
        padding: 5px 10px;
      input:valid {
        background-color: #eeeeee;
    <h2>:valid selector example</h2>
      <input type="email" value="[email protected]">

In the given example when typing an illegal e-mail address, the styling disappears.

Browser support

chrome edge firefox safari opera
10.0+ 12.0+ 4.0+ 10.1+ 10.0+

Practice Your Knowledge

What is the usage and function of the 'valid' CSS pseudo-class?

Quiz Time: Test Your Skills!

Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.

Do you find this helpful?