Change Placeholder Color in CSS (::placeholder)
To change the color of placeholder text, style the ::placeholder pseudo-element on the input or textarea. It works in all current browsers without prefixes.
Demo:
Basic placeholder color
Target all fields at once, or one specific input. Set opacity: 1: Firefox gives placeholders reduced opacity by default, so the same color looks lighter there than in Chrome without it.
::placeholder {
color: #64748b;
opacity: 1;
}
/* One field only */
input.search::placeholder {
color: #1d4ed8;
}
What you can style
::placeholder accepts text properties: color, opacity, font-*, letter-spacing, text-transform and similar. It doesn’t accept layout properties like padding or margin; those come from the input itself.
textarea::placeholder {
color: #64748b;
font-style: italic;
letter-spacing: 0.02em;
}
Change it on focus
Fade the placeholder when the field is focused, so it stays as a hint but makes clear the user can type.
input::placeholder {
transition: opacity 0.2s;
}
input:focus::placeholder {
opacity: 0.4;
}
Style the input while the placeholder shows
:placeholder-shown (a pseudo-class, one colon) matches the input while it’s empty and showing its placeholder. Use it for floating labels or to style empty fields.
input:placeholder-shown {
border-color: #cbd5e1;
}
input:not(:placeholder-shown) {
border-color: #1d4ed8; /* has a value */
}
Keep placeholders readable
Light gray placeholders often fail contrast. On a white field, #767676 is the lightest gray that reaches the 4.5:1 ratio for normal text. And don’t use a placeholder as the only label: it disappears as soon as someone types. Always keep a real <label>; see the HTML input types guide for the right field for each kind of data.
FAQ
How do I change the placeholder color in CSS?input::placeholder { color: #64748b; opacity: 1; }
Why is my placeholder lighter in Firefox?
Firefox applies a default opacity to placeholders. Add opacity: 1.
Do I still need -webkit-input-placeholder?
No. The standard ::placeholder works in all current browsers. The prefixed versions were only needed for browsers from before 2017.
Related: HTML input types, CSS ::before and ::after, CSS class selectors and HTML tips.