concept

Accessible form state — CSS reference

Make form errors identifiable with text and semantic state, not color alone. Here the input has a visible label, an error message linked by aria-describedby, and aria-invalid after validation has identified an error. The CSS only supplies a visual cue. Update state and message together when validation changes.

Formal Syntax & Structure

css syntaxcss
input[aria-invalid="true"] { border-color: #b91c1c; }

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>accessible-form-state</title><style>body{margin:8px;font:16px/1.5 sans-serif;color:black;background:white}#a{box-sizing:border-box}#a[aria-invalid="true"]{border:2px solid #b91c1c}</style><body><label for="a">Email address</label><input id="a" type="email" value="invalid" aria-invalid="true" aria-describedby="err"><p id="err">Enter a valid email address.</p></body></html>
CSS Reference