The ::placeholder pseudo-element styles the light hint text inside <input> and <textarea> fields. It helps you match placeholder text to your form design without affecting what users actually type.
01
Hint text
Before typing.
02
color
Gray or brand.
03
font-style
Italic hints.
04
opacity
Fade on focus.
05
input
Text fields.
06
textarea
Multi-line.
Fundamentals
Introduction
The CSS ::placeholder selector targets the placeholder text inside form fields. Placeholder text is the light gray hint shown before a user types, set with the HTML placeholder attribute.
It works on <input> and <textarea> elements, letting you customize color, font size, font style, opacity, and other text properties for a more polished form appearance.
Definition and Usage
Use ::placeholder on its own or scoped to a field: input::placeholder or textarea::placeholder. Styles apply only to the hint text — not to the value the user enters.
💡
Beginner Tip
Placeholders are hints, not labels. Always pair fields with a <label> for accessibility. Use ::placeholder to improve visual design, not to replace field names.
Foundation
📝 Syntax
The syntax for the ::placeholder pseudo-element is:
syntax.css
::placeholder{/* CSS properties */}
The ::placeholder pseudo-element targets the hint text of form elements that have a placeholder attribute.
Modern browsers support the standard ::placeholder syntax. For very old browsers, you may still see these prefixed versions:
placeholder-prefixes.css
/* Legacy prefixes (optional for old browsers) */::-webkit-input-placeholder{color:#94a3b8;}::-moz-placeholder{color:#94a3b8;opacity:1;}:-ms-input-placeholder{color:#94a3b8;}
Syntax Rules
The element must have a placeholder attribute in HTML.
Use double colon ::placeholder — it is a pseudo-element, not a pseudo-class.
Scope with element selectors: input::placeholder avoids affecting unrelated elements.
Combine with :focus: input:focus::placeholder for fade effects.
Set opacity: 1 on Firefox when using ::-moz-placeholder.
Related Selectors
:focus — style the field when the user clicks into it
:disabled — style inactive form controls
[placeholder] — attribute selector to target fields with placeholders
::selection — style text the user highlights
input — styles the actual typed value, not the placeholder
Cheat Sheet
⚡ Quick Reference
Question
Answer
Selector type
Pseudo-element
When it applies
Field is empty and showing hint text
Required HTML
placeholder="..." attribute
Most used properties
color, font-style, opacity
Common pattern
input::placeholder { color: #94a3b8; }
Browser support
All modern browsers
Context
When to Use ::placeholder
::placeholder is ideal for polishing form hint text:
Login and signup forms — Match placeholder color to your brand palette.
Search bars — Use lighter, italic hints like “Search products…”
Contact forms — Style textarea placeholders differently from single-line inputs.
Focus interactions — Fade placeholders when the user starts typing.
Consistent typography — Align hint font size with your design system.
Preview
👀 Live Preview
Click into the fields below to see placeholder styling. Hints fade slightly on :focus:
Hands-On
Examples Gallery
Practice ::placeholder with basic styling, scoped selectors, focus fades, and complete form layouts.
📜 Core Patterns
Style placeholder hint text with color, font, and opacity.
Example 1 — Basic ::placeholder styling
Apply gray italic styling to all placeholder text in a form.
placeholder-form.html
<style>::placeholder{color:#94a3b8;font-style:italic;font-size:0.875rem;}input,textarea{padding:0.5rem 0.75rem;border:2px solid #cbd5e1;border-radius:0.4rem;width:100%;}</style><form><inputtype="text"placeholder="Enter your name"><textareaplaceholder="Your message"></textarea></form>
The placeholder text appears in gray italic while the field is empty. Once the user types, normal input text styling takes over and ::placeholder no longer applies.
Example 2 — Different styles for input and textarea
Scope placeholder styles separately so single-line and multi-line hints look distinct.
When the field receives focus, input:focus::placeholder lowers opacity so the hint recedes while the user types. A short transition makes the change feel smooth.
Example 4 — Login form with branded placeholders
Style email and password placeholders with a consistent brand color inside a form wrapper.
Wrapping the form in .login-form scopes placeholder styling to that context. Typed text uses the darker input color, while hints stay in the brand indigo tone.
Tips
💬 Usage Tips
Use readable contrast — Placeholder text should be lighter than input text but still legible.
Scope selectors — Use input::placeholder instead of a global ::placeholder when possible.
Fade on focus — Lower opacity with input:focus::placeholder for a polished feel.
Keep hints short — Placeholders work best as brief examples, not instructions.
Separate typed text — Style the input element itself for the value users type.
Test in Firefox — Set opacity: 1 on ::-moz-placeholder if using legacy prefixes.
Watch Out
⚠️ Common Pitfalls
Replacing labels — Placeholders disappear when users type; they are not accessible field names.
Low contrast — Very light placeholder text can fail WCAG readability guidelines.
Wrong properties — Background, border, and padding usually do not work on ::placeholder.
Styling typed text — ::placeholder does not affect values the user enters; style input instead.
Missing placeholder attr — Without the HTML attribute, there is no hint text to style.
Single colon syntax — Use ::placeholder (pseudo-element), not :placeholder.
A11y
♿ Accessibility
Always use labels — Every input needs a <label> or aria-label, not just a placeholder.
Do not hide critical info — Required format hints belong in visible label text or help text.
Maintain contrast — Placeholder color should meet minimum contrast against the field background.
Avoid placeholder-only forms — Screen readers may not always announce placeholder text reliably.
High-contrast mode — Test that hints remain visible when users enable OS high-contrast settings.
🧠 How ::placeholder Works
1
HTML placeholder attribute
The field has placeholder="Enter your name" in HTML.
HTML
2
Field is empty
The browser displays the hint text inside the input or textarea.
Display
3
::placeholder styles apply
Your CSS color, font, and opacity rules target only the hint text.
CSS
=
✎
User types — hint disappears
Typed value uses normal input styles; placeholder styling is no longer visible.
Compatibility
🖥 Browser Compatibility
The ::placeholder pseudo-element is supported in all modern browsers.
✓ Baseline · Modern browsers
Placeholder styling everywhere
::placeholder works in Chrome, Firefox, Safari, Edge, and Opera without vendor prefixes.
98%Global support
Google Chrome57+ · Desktop & Mobile
Full support
Mozilla Firefox51+ · Desktop & Mobile
Full support
Apple Safari10.1+ · macOS & iOS
Full support
Microsoft Edge79+ (Chromium)
Full support
Opera44+
Full support
::placeholder pseudo-element98% supported
Bottom line: Safe for modern form UI. Add legacy prefixes only if you must support very old browsers.
Wrap Up
🎉 Conclusion
The ::placeholder selector is a useful tool for enhancing form elements by customizing hint text appearance. With control over color, font, and opacity, you can create a more visually appealing and consistent user experience.
Remember that placeholders are hints, not labels. Pair ::placeholder styling with proper <label> elements and accessible help text for the best results.
Put critical validation rules only in placeholders
Confuse ::placeholder with input text styles
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about ::placeholder
Use these points when styling form hint text.
5
Core concepts
💬01
Hint text only
Not typed value.
Purpose
::02
Pseudo-element
Double colon.
Syntax
🎨03
color & font
Main props.
Style
:focus04
Fade on focus
UX polish.
Tip
🌐05
98% support
All browsers.
Compat
❓ Frequently Asked Questions
The ::placeholder pseudo-element targets the hint text shown inside form fields before the user types. It lets you style placeholder color, font, opacity, and other text properties without affecting the actual input value.
::placeholder works on input and textarea elements that have a placeholder attribute. Common types include text, email, password, search, tel, url, and number.
No. ::placeholder only affects the hint text. Once the user enters a value, normal input styles apply instead.
Most browsers only allow a limited set of properties on ::placeholder — mainly color, font, opacity, and text-decoration. Background and border usually do not apply to the placeholder text itself.
No. Placeholders are hints, not accessible labels. Always use a visible label or aria-label so screen reader users know what each field is for.