CSS Placeholder Color
Placeholder text — the hint inside an empty input — has its own
color, set with the ::placeholder pseudo-element. Pick a color
and an opacity below, then click into the field and out again: the
placeholder fades to half opacity while the field is focused, live.
Click into the field and the placeholder fades; click out and it comes back. Type something and the placeholder disappears entirely — that is how placeholders behave: they are a hint, not a value.
Contrast ratio: —
The demo color #9CA3AF on white is only 2.54:1 —
fine for a hint, but it would fail WCAG AA as body text. If your placeholder
is the only label a user sees, use a darker gray such as
#6B7280 (4.83:1) — or better, keep a real visible label next to
the field.
How to style input placeholder color with the modern ::placeholder pseudo-element — live demo with a real working input, focus fade, opacity control, and legacy vendor-prefix fallback.
Style placeholder text with ::placeholder — input::placeholder { color: #9CA3AF; }. It is the modern standard in every current browser; the old vendor prefixes are only a legacy fallback. Try it live: pick a color, type in the field, and click in and out to see the focus fade.
The modern standard: ::placeholder
Placeholder text is styled with the ::placeholder
pseudo-element. It has been the standard for years and works in every current
browser — Chrome, Edge, Firefox, and Safari all support it without a prefix.
This is the rule to write first:
input::placeholder {
color: #9CA3AF;
opacity: 1;
}
Only a few properties apply to placeholders — color,
opacity, and font properties such as font-size and
font-style. Layout properties, backgrounds, and borders do not:
the placeholder lives inside the input, and the input owns its box.
Vendor prefixes are a legacy fallback, not the way to write it
Older articles — and some older sites — show a stack of prefixed selectors. They were needed a decade ago, when each browser had its own version of the feature. Today they are only a fallback for very old browsers:
| Selector | For | Status |
|---|---|---|
::placeholder | All current browsers | The standard — write this first |
::-webkit-input-placeholder | Old Chrome, Safari, and Edge (before Chromium) | Legacy fallback |
::-moz-placeholder | Firefox 4–18 | Legacy fallback |
:-ms-input-placeholder | Internet Explorer 10–11 | Legacy fallback |
The generator above writes the modern rule first and the prefixed rules after it, so old browsers pick up the fallback and modern browsers use the standard. If your audience is on current browsers — and almost everyone's is — the prefixed rules do nothing and can be left out entirely.
The Firefox opacity quirk
Firefox gives placeholder text a reduced opacity by default (about 0.54 in
older versions), so the same color looks paler in Firefox than in Chrome.
The fix is one line in the legacy ::-moz-placeholder rule —
opacity: 1 — which tells Firefox to use the color exactly as
written. In the modern ::placeholder rule, opacity
is yours to set: 1 for a solid placeholder, lower for a fainter hint. The
demo lets you try both, and the contrast readout shows what the placeholder
actually appears as.
The :focus fade
A common pattern is to fade the placeholder when the field is focused, so the user's attention moves to what they are typing. The demo does it with a 250ms transition:
input::placeholder {
color: #9CA3AF;
transition: opacity 250ms ease;
}
input:focus::placeholder {
opacity: 0.5;
}
The transition goes on the ::placeholder rule and the
opacity change on :focus::placeholder. Try it above: click into
the field and the hint fades, click out and it returns.
A placeholder is not a label
Placeholder text disappears the moment the user types, so it cannot be the
only label on a field — once someone starts typing they can no longer see
what the field was for, and screen readers do not reliably announce
placeholders. Always pair an input with a real <label>,
and use the placeholder only for a hint or an example (“e.g.
[email protected]”). And keep the color readable: the common light-gray
placeholder #9CA3AF on white is 2.54:1, which would fail WCAG AA
as text. A darker gray such as #6B7280 (4.83:1) is a safer
default when the hint matters.
Frequently asked questions
How do I change placeholder color in CSS?
Use the ::placeholder pseudo-element: input::placeholder { color: #9CA3AF; }. It works in all current browsers with no prefix. The old prefixed selectors (::-webkit-input-placeholder, ::-moz-placeholder, :-ms-input-placeholder) are only a fallback for very old browsers.
Why is my placeholder color not working in Firefox?
Firefox applies a reduced opacity to placeholders by default, so the color looks paler than in Chrome. Set opacity: 1 in the rule — input::placeholder { color: #9CA3AF; opacity: 1; } — and Firefox uses the color exactly as written. Older Firefox (4–18) needs the same line in ::-moz-placeholder.
Do I still need vendor prefixes for ::placeholder?
No, not for current browsers — ::placeholder has been the standard for years and works unprefixed in Chrome, Edge, Firefox, and Safari. Keep the prefixed rules only if you must support Internet Explorer 10–11, Firefox 4–18, or pre-Chromium Edge.
How do I fade a placeholder on focus?
Put a transition on ::placeholder and a lower opacity on :focus::placeholder: input::placeholder { transition: opacity 250ms ease; } input:focus::placeholder { opacity: 0.5; }. The demo above shows it live.
Can a placeholder replace the label on an input?
No. Placeholder text disappears when the user types, and screen readers do not reliably announce it. Always use a real <label> for the field name, and use the placeholder only for a hint or an example value.
Related tools
Tutorials · CSS Text Color · CSS Color Basics · CSS Background Color · HTML Text Color · Contrast Checker