Sub topic 4
Hint text, and why placeholders are not labels
This chapter assumes you know basic HTML form elements and how a <label> is tied to an input with for and id. You should also be comfortable with basic CSS. No JavaScript is needed here.
The problem with placeholders
A placeholder is the grey text inside an empty input, set with the placeholder attribute. Designers like it because it saves space. It causes several problems when it stands in for a label or carries instructions:
- It disappears as soon as the user types, so they cannot check what was asked.
- Browsers render it in a light grey that often fails the 4.5:1 text contrast ratio.
- Users may read a filled-looking field as already completed, or skip it.
- It is not a reliable accessible name. Screen readers may use it as a fallback, but that is not guaranteed across browsers and assistive technology.
- Long placeholder text is cut off in narrow fields.
The rule is simple. Every field gets a visible label, as the earlier chapters set out. A placeholder is, at most, an optional extra, and nothing important should depend on it.
Hint text
Hint text is persistent text, placed near the label, that tells users what to enter or in what format. It stays visible while they type. Use it for format examples ("For example, SW1A 1AA"), constraints ("Must be at least 12 characters"), and reasons for asking ("We only use this to confirm your delivery").
Keep a hint short and put it between the label and the input. Users read in that order, so they see the guidance before they type.
Connecting a hint to its input
A hint that is only visually near the input is not available to screen reader users. Link it with aria-describedby, which points to the id of the element holding the description. A screen reader announces the label first, then the description.
<label for="postcode">Postcode</label>
<p id="postcode-hint">For example, SW1A 1AA</p>
<input id="postcode" name="postcode" type="text" autocomplete="postal-code" aria-describedby="postcode-hint">The aria-describedby value is an id, without a #. You can list several ids separated by spaces, which is how a hint and an error message can both be attached to one field.
Styling hints
Style hint text so it is easy to read, not faint.
.hint {
margin: 0 0 0.25rem;
color: #4b5563;
font-size: 1rem;
}The colour #4b5563 on a white background gives a contrast ratio of about 7.5:1, which passes the 4.5:1 minimum. Avoid making hints smaller than the label.
When a placeholder is acceptable
A short, non-essential example can sit in a placeholder if the same information is not needed to complete the field. Treat it as decoration. If removing it would make the field harder to fill in, move the text into a hint.
Common mistakes
| Mistake | Why it fails | Fix |
|---|---|---|
| Placeholder used as the only label | Label vanishes on input; weak accessible name | Add a visible `<label>` |
| Hint placed after the input without `aria-describedby` | Screen reader users never hear it | Link it with `aria-describedby` |
| Hint text in pale grey | Fails contrast | Use at least 4.5:1 |
| Hint repeated as the error message | Gives no new information | Write a specific error, as a later chapter covers |
Exercise
A sign-up form has a password field whose only guidance is the placeholder "At least 12 characters". Name two problems with this, and write the HTML that fixes them.
Show answer
The guidance disappears once the user starts typing, and the placeholder is not a reliable label or description for screen readers. Fix it with a visible label and a linked hint: <label for="password">Password</label> <p id="password-hint">Must be at least 12 characters</p> <input id="password" name="password" type="password" autocomplete="new-password" aria-describedby="password-hint">