CSS ::placeholder Pseudo-Element

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The ::placeholder pseudo-element styles the hint text shown inside an <input> or <textarea> before the user types.

It does not style the typed value. Only a limited set of text-like properties apply (similar to ::first-line): mainly color, font, opacity, and text decoration.

Baseline Widely available.

Supported across modern browsers. Prefer the standard ::placeholder form.

Warning — not a label.

Placeholders disappear on input and must not replace a visible, associated <label>.

Deprecated — vendor prefixes.

Skip ::-webkit-input-placeholder, ::-moz-placeholder, and :-ms-input-placeholder unless you must support very old browsers.

CSS Syntax

syntax.css
::placeholder { /* styles */ }

Commonly scoped: input::placeholder or textarea::placeholder.

Selector Patterns

PatternDescriptionTry it
::placeholderStyle placeholder text on matching controlsTry it
input::placeholderInputs onlyTry it
color + opacityReadable muted hint colorTry it
italic hintfont-style on the hintTry it
input vs textareaDifferent styles per control typeTry it
currentColorMatch the control’s text colorTry it

How to Use ::placeholder

Add a placeholder attribute, keep a real label, then style the hint.

  1. Associate a visible <label> with the control.
  2. Add a short placeholder hint in HTML.
  3. Write input::placeholder { … } with text properties only.
  4. Check contrast so the hint is readable but not mistaken for real input.
PieceRequired?Role
placeholder attributeYesProvides the hint text to style
<label>Yes (a11y)Names the field; not replaced by placeholder
Text propertiesYescolor, font, opacity, text-decoration
:placeholder-shownOptionalStyles the control while the hint is visible

Live Preview

Pick a hint color. The empty field uses ::placeholder; typing replaces the hint with normal input text.

Leave the field empty to see the styled hint; type to hide it.

Placeholder preview

Placeholder color: #64748b

CSS Examples

Each snippet focuses on ::placeholder. Use Try It Yourself for a live editor.

Example 1 — Color the Hint

Set a clear, muted color for placeholder text.

CSS
input::placeholder {
  color: #64748b;
  opacity: 1;
}
Try It Yourself

How It Works

  1. Add a placeholder. The HTML attribute supplies the hint string.
  2. Select ::placeholder. Only the hint is targeted.
  3. Set color. Choose a muted but readable shade.
  4. Set opacity: 1. Keeps color consistent across browsers that fade placeholders by default.

Example 2 — Italic Hint Text

Use font style to make hints look different from typed text.

CSS
input::placeholder {
  font-style: italic;
  color: #64748b;
}
Try It Yourself

How It Works

  1. Style the pseudo-element. font-style applies to the hint only.
  2. Keep input text normal. The control’s own font is unchanged.
  3. Type a value. The italic hint disappears; upright text appears.
  4. Clear the field. The italic placeholder returns.

Example 3 — Input vs Textarea

Scope styles when single-line and multi-line hints should look different.

CSS
input::placeholder {
  color: #2563eb;
}

textarea::placeholder {
  color: #64748b;
  font-style: italic;
}
Try It Yourself

How It Works

  1. Scope by element. input::placeholder and textarea::placeholder stay separate.
  2. Style inputs with a stronger hint color for short fields.
  3. Style textareas with a softer, italic hint for longer copy.
  4. Keep labels. Each control still has its own accessible name.

Edge Cases & Pitfalls

Most issues are about accessibility, not syntax.

a11y

Never replace labels

Screen readers and sighted users need a lasting label. Put examples outside the field with aria-describedby when needed.

contrast

Balance contrast

Too light fails WCAG; too strong looks like real input. Aim for readable gray that still differs from typed text.

props

Limited properties

Only a ::first-line-like subset applies. Do not expect background or border on the placeholder itself.

vs shown

Not the same as :placeholder-shown

::placeholder styles the hint. :placeholder-shown matches the control while that hint is visible.

opacity

Browser opacity defaults differ

Set color explicitly and often opacity: 1 so Firefox, Chrome, and Safari look alike.

Browser Support

::placeholder is a browser CSS pseudo-element. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

::placeholder

Standard form widely supported since ~2020. Older engines needed vendor prefixes.

97% Modern browsers
Google Chrome 57+
Full support
Mozilla Firefox 51+
Full support
Apple Safari 10.1+
Full support
Microsoft Edge 79+
Full support
Opera 44+
Full support
Samsung Internet 7+
Full support
::placeholder Widely supported

Bottom line: Safe for modern forms. Prefer unprefixed ::placeholder. Not a server runtime API.

Key Takeaways

  • Role: style empty-state hint text in inputs and textareas.
  • Limits: text-like properties only — not full box styling.
  • A11y: always keep a real label; placeholders are optional hints.
  • Tip: set color (and often opacity: 1) for cross-browser consistency.

One line: ::placeholder styles the hint text inside empty form fields — never the typed value.

Frequently Asked Questions

It styles the placeholder hint text inside an input or textarea — color, font, opacity, and similar text properties — without styling the value the user types.
Elements that show a placeholder attribute: input (text, email, search, tel, url, password, number, and similar) and textarea.
Only a limited set of properties apply (similar to ::first-line). Prefer color, font, opacity, and text-decoration. Background and border usually do not style the placeholder text itself.
::placeholder styles the hint text. :placeholder-shown is a pseudo-class that matches the control while the placeholder is visible (empty value).
No. Placeholders disappear when typing and are weak for accessibility. Always use a proper label; keep placeholders as short hints only.
No. It is a browser CSS pseudo-element, not a Node.js feature.

Next: :read-only

Style form controls that the user cannot edit.

:read-only tutorial →

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.

8 people found this page helpful