CSS ::placeholder: change placeholder color and font styles
Use CSS ::placeholder to change the color, weight, or slant of a field’s hint. Use :placeholder-shown when you need to style the field itself while the hint is visible. Put a short example in the HTML placeholder attribute and give the field a persistent <label>.
Set the hint color and font
input::placeholder matches the hint in an <input>. Use textarea::placeholder for a multiline field. The rule below changes the hint while leaving typed text to inherit its own style. Prefix it with .contact to apply it only to one form.
input::placeholder {
color: #334155;
font-style: italic;
opacity: 1;
}
W3C CSS Pseudo-Elements specification
Run the complete form example
Save the complete example as placeholder-demo.html in UTF-8 and open it in a browser. No server or dependencies are required.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contact example</title>
<style>
body { margin: 2rem auto; max-width: 32rem; padding: 0 1rem;
font: 1rem/1.5 system-ui, sans-serif; }
.contact label, .contact small { display: block; }
.contact label { margin-top: 1rem; font-weight: 700; }
.contact input, .contact textarea {
box-sizing: border-box;
width: 100%;
padding: .65rem;
font: inherit;
color: #111827;
background: #fff;
border: 2px solid #475569;
border-radius: .4rem;
}
.contact input::placeholder {
color: #334155;
font-style: italic;
opacity: 1;
}
.contact textarea::placeholder {
color: #1e3a8a;
font-weight: 600;
opacity: 1;
}
.contact input:placeholder-shown, .contact textarea:placeholder-shown {
border-style: dashed;
}
</style>
</head>
<body>
<h1>Contact example</h1>
<form class="contact">
<label for="email">Email address</label>
<input id="email" type="email" placeholder="name@example.com"
autocomplete="email">
<label for="message">Message</label>
<textarea id="message" rows="3" aria-describedby="message-help"
placeholder="Example: Change a shipping address"></textarea>
<small id="message-help">Briefly describe what you need help with.</small>
</form>
</body>
</html>
- The email hint is dark slate and italic. The message hint is dark blue and semibold. Typed values use the field’s regular text color.
- Type into either field to replace the hint with the value. Its border changes from dashed to solid. Clear the field to restore the hint and dashed border.
- Change
font-style: italictonormalin the email hint rule. Check that only the hint changes, then restore the original declaration.
Style the field while it shows a hint
::placeholder is a pseudo-element for the displayed hint. :placeholder-shown is a pseudo-class on the control. Put border and background declarations on the control, as in the example. A space in <textarea> still counts as input.
Keep hints readable and labels visible
If the hint still looks faint, inspect the applied selector and opacity in developer tools. Setting opacity: 1 displays the chosen color without making it semitransparent through this property. Recheck the foreground against the actual field background. The Web Content Accessibility Guidelines (WCAG) require at least 4.5:1 for normal-sized text, including hints.
Keep required instructions visible beside the field. Associate the instructions with aria-describedby, as on the message field. The label and instructions then remain available after someone starts typing.
HTML rules for placeholders and labels · WCAG minimum text contrast




