:valid

The pseudo-class CSS :valid representa qualsevol element <input> o altre <form> el contingut del qual es valida correctament. Això permet fer, fàcilment, que els camps vàlids adoptin una aparença que ajudi a l'usuari a confirmar que les seves dades estan formatades correctament.

/* Selecciona qualsevol <input> vàlid */
input:valid {
  background-color: powderblue;
}

Aquesta pseudo-class és útil per ressaltar els camps correctes per a l'usuari.

Sintaxi

:valid

Exemples

Vegeu :invalid com exemple.

Especificacions

Especificació Estat Comentari
HTML Living Standard
The definition of ':valid' in that specification.
Living Standard Cap canvi.
HTML5
The definition of ':valid' in that specification.
Recommendation Defineix la semàntica respecte a l'HTML i la validació de restriccions.
Selectors Level 4
The definition of ':valid' in that specification.
Working Draft Definició inicial.
Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
:validChrome Full support 10Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 10Safari Full support 5WebView Android Full support 37Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 5Samsung Internet Android Full support 1.0
Applies to <form> elementsChrome Full support 40Edge No support NoFirefox Full support 13IE No support NoOpera Full support 27Safari Full support 9WebView Android Full support 40Chrome Android Full support 40Firefox Android Full support 14Opera Android Full support 27Safari iOS Full support 9Samsung Internet Android Full support 4.0

Legend

Full support  
Full support
No support  
No support

Vegeu també