CSS Reference ยท Pseudo-elements
The ::placeholder pseudo-element
Reference for the CSS ::placeholder pseudo-element: style the hint text of inputs and textareas, with contrast, opacity and accessibility notes.
The ::placeholder pseudo-element styles the hint text shown inside an <input> or <textarea> while the field is empty and has a placeholder attribute. The text disappears as soon as the user types.
You can change its color, font and similar text properties. Browsers give placeholders a lighter default color so they look different from real input, which often leads to low contrast.
input::placeholder { color: #868e96; font-style: italic; }
Try it
Syntax
input::placeholder { } textarea::placeholder { }
| Property | Value |
|---|---|
| Applies to | Text inputs and <textarea> with a placeholder attribute |
| Inherited | Inherits from the field |
| Animatable | Its properties follow their own animation rules |
Values
The pseudo-element takes no arguments. Text-related properties apply:
| Group | Examples |
|---|---|
| Color | color, opacity, background-color |
| Fonts | font-*, line-height |
| Text | text-transform, text-decoration, letter-spacing, text-align, text-indent |
Usage notes
- Set
opacitytoo. Some browsers dim placeholders with a defaultopacity. If your chosencolorlooks washed out, setopacity: 1. - Contrast. Gray hints are hard to read. Aim for the same contrast ratio as normal text (4.5:1).
- Not a label. A placeholder vanishes when typing starts and is not a reliable name for the field. Always use a real
<label>; use the placeholder only for an example format. - Match the field. To style the field differently when the hint is visible, use
:placeholder-shownon the input itself. - Number and date inputs. Types that show native UI (date, color) have no placeholder.
- Legacy prefixes. Very old browsers used
::-webkit-input-placeholderand::-moz-placeholder. Do not group them with::placeholder, because an unknown selector invalidates a whole list.
Browser support
Supported in every current browser.