Good Code
The good version ties guidance and the current error to the input, and marks the field invalid when validation fails.
Lesson 07
Connect help and error text to the field so validation feedback is announced with the control.
<label for="password">Password</label>
<!-- aria-describedby connects both guidance and error text to the field. -->
<input
id="password"
name="password"
type="password"
aria-describedby="password-help password-error"
aria-invalid="true"
/>
<p id="password-help">Use at least 12 characters.</p>
<p id="password-error">Password is too short.</p><label>Password</label>
<!-- Nearby text is visual only unless it is programmatically connected. -->
<input name="password" type="password" />
<p class="help">Use at least 12 characters.</p>
<p class="error">Too short.</p>The good version ties guidance and the current error to the input, and marks the field invalid when validation fails.
The bad version places text near the field visually, but the input has no durable relationship to the help or error message.