::placeholder
Example
input::placeholder {
color: #ccc;
}input::placeholder {
color: #6b6b6b;
}#6b6b6b stays readable on a white field, while #ccc is too faint for many users.
Common mistakes
- Using the placeholder as the only label, so it disappears once the user types.
- Light gray placeholder text that fails contrast checks.
Key points
- Placeholder text keeps enough contrast with the field background.
- Fields have a real
<label>; the placeholder isn't the only label. - Only text styles are set on
::placeholder, as box properties likemarginare ignored.
Interview questions
Why shouldn't the placeholder replace a label?
It disappears when the user types, is often low contrast and is not a reliable label. Use a visible <label> and keep the placeholder for an example value.
Which properties work on ::placeholder?
Text and background styles, such as color, font, opacity, letter-spacing and background-color. Box properties like margin and padding do not apply.