:optional

La pseudo-class CSS :optional representa qualsevol element <input>, <select> o <textarea> que no t茅 l'atribut required establert en ell.

/*  Selecciona qualsevol <input> opcional */
input:optional {
  border: 1px dashed black;
}

Aquesta pseudo-class 茅s 煤til per als camps d'estil que no s贸n obligatoris per enviar en un formulari.

Nota: La pseudo-class :required selecciona els camps de formulari obligatoris.

Sintaxi

:optional

Exemples

Veure :invalid com exemple.

Especificacions

Especificaci贸 Estat Comentari
HTML Living Standard
The definition of ':optional' in that specification.
Living Standard Sense canvis.
HTML5
The definition of ':optional' in that specification.
Recommendation Defineix la sem脿ntica d'HTML i la validaci贸 de restriccions.
Selectors Level 4
The definition of ':optional' in that specification.
Working Draft Sense canvis.
CSS Basic User Interface Module Level 3
The definition of ':optional' in that specification.
Recommendation Defineix la pseudo-classe, per貌 no la sem脿ntica associada.

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)

Descripci贸 Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Suport b脿sic 10.0 (Yes) 4.0 (2) 10 10.0 5.0
Descripci贸 Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Suport b脿sic 4.4 (Yes) 4.0 (2) No support 10.0 5.0

Vegeu tamb茅