CSS ::placeholder Selector

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
Pseudo-elements

What You’ll Learn

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.

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.

📝 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.

Basic Example

placeholder.css
::placeholder {
  color: #94a3b8;
  font-style: italic;
  font-size: 0.875rem;
  opacity: 1;
}
input::placeholder textarea::placeholder input:focus::placeholder .form input::placeholder

Allowed Properties

Property groupExamplesWorks?
Color & opacitycolor, opacityYes
Fontfont-size, font-style, font-weightYes
Texttext-decoration, text-transform, letter-spacingYes
Box modelbackground, border, paddingNo (in most browsers)

Legacy Vendor Prefixes

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

⚡ Quick Reference

QuestionAnswer
Selector typePseudo-element
When it appliesField is empty and showing hint text
Required HTMLplaceholder="..." attribute
Most used propertiescolor, font-style, opacity
Common patterninput::placeholder { color: #94a3b8; }
Browser supportAll modern browsers

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.

👀 Live Preview

Click into the fields below to see placeholder styling. Hints fade slightly on :focus:

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>
  <input type="text" placeholder="Enter your name">
  <textarea placeholder="Your message"></textarea>
</form>
Try It Yourself

How It Works

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.

placeholder-scoped.css
input::placeholder {
  color: #64748b;
  font-weight: 500;
}

textarea::placeholder {
  color: #94a3b8;
  font-style: italic;
  line-height: 1.5;
}
Try It Yourself

How It Works

Scoping to input::placeholder and textarea::placeholder gives you finer control. Input hints can be bolder; textarea hints can be softer and italic.

📄 Focus & Forms

Enhance UX with focus fades and complete form styling.

Example 3 — Fade placeholder on focus

Reduce placeholder opacity when the user clicks into the field so typed text stands out.

placeholder-focus.css
input::placeholder {
  color: #94a3b8;
  opacity: 1;
  transition: opacity 0.2s ease;
}

input:focus::placeholder {
  opacity: 0.4;
}
Try It Yourself

How It Works

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.

placeholder-login.css
.login-form input::placeholder {
  color: #6366f1;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  opacity: 0.75;
}

.login-form input {
  color: #1e293b;
}
Try It Yourself

How It Works

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.

💬 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.

⚠️ 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.

♿ 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.

🖥 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 Chrome 57+ · Desktop & Mobile
Full support
Mozilla Firefox 51+ · Desktop & Mobile
Full support
Apple Safari 10.1+ · macOS & iOS
Full support
Microsoft Edge 79+ (Chromium)
Full support
Opera 44+
Full support
::placeholder pseudo-element 98% supported

Bottom line: Safe for modern form UI. Add legacy prefixes only if you must support very old browsers.

🎉 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.

💡 Best Practices

✅ Do

  • Always include visible <label> elements
  • Use input::placeholder for scoped styling
  • Keep placeholder hints short and helpful
  • Ensure sufficient color contrast
  • Style typed text on the input element separately

❌ Don’t

  • Use placeholders as the only field label
  • Make placeholder text too faint to read
  • Expect background/border to work on placeholders
  • Put critical validation rules only in placeholders
  • Confuse ::placeholder with input text styles

Key Takeaways

Knowledge Unlocked

Five things to remember about ::placeholder

Use these points when styling form hint text.

5
Core concepts
:: 02

Pseudo-element

Double colon.

Syntax
🎨 03

color & font

Main props.

Style
:focus 04

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.

Practice in the Live Editor

Open the HTML editor and experiment with ::placeholder, focus fades, and form hint styling.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful