English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS reference manual

CSS @rule (RULES)

CSS attribute大全

CSS :valid Selector

Complete CSS Selector Reference Manual

Online Example

If the value entered in the input element is valid, set it to yellow:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Basic Tutorial(oldtoolbag.com)</title>/title> 
<style>
input:valid
{
    background-color: yellow;
}
</style>
</head>
<body>
<h3>:valid selector example demonstration.</h3>
<input type="email" value="[email protected]"> />
<p>Please enter an invalid e-email address, see style changes.</p>
</body>
</html>
Test to see ‹/›

Definition and Usage

:valid selector sets the specified style when the value of a form element needs to be validated according to the specified conditions.

Note:  :valid selector only affects elements that can specify a range of values, such as min and max attributes in input elements, and correct email fields, valid numeric fields, etc.

Browser Compatibility

The numbers in the table indicate the first browser version that supports this attribute.

Selector




:valid10.010.04.05.010.0

CSS Syntax

:valid
{
    css declaration;
}

Related Pages

CSS Selector :invalid

Complete CSS Selector Reference Manual