HTML/CSSIntermediate#css#forms#pseudo-classes

How do you style form validation states using CSS pseudo-classes?

:valid and :invalid style inputs based on constraint validation results, :required/:optional target mandatory fields, and :placeholder-shown detects empty inputs still showing placeholder text — enabling live feedback without JavaScript.

Example
input:invalid { border-color: red; }
input:valid { border-color: green; }
input:required:placeholder-shown { border-color: orange; }

Related Questions

1
HTML/CSSAdvanced#css#design-systems

What is the difference between rem-based spacing scale and arbitrary pixel values in design systems?

Open
2
HTML/CSSAdvanced#css#performance

How does the 'will-change' property affect rendering performance?

Open
3
HTML/CSSIntermediate#html#semantics

What is the difference between HTML5's <section>, <article>, and <aside>?

Open