CSS :placeholder-shown Pseudo-Class

Beginner
2 examples
Updated: Nov 2026

Definition and Usage

The :placeholder-shown pseudo-class matches an input or textarea while it is empty and showing placeholder text. Use it to style empty fields differently from filled ones.

CSS Syntax

syntax.css
input:placeholder-shown {
  border-color: #94a3b8;
}

Key Uses

PatternPurposeTry it
:placeholder-shownEmpty control showing its placeholderTry it
with :not()Style filled fields after the placeholder hidesTry it

CSS Examples

Muted empty fields

example.css
input:placeholder-shown {
  border-color: #94a3b8;
  background: #f8fafc;
}
Try It Yourself

Filled vs empty

example.css
input:not(:placeholder-shown) {
  border-color: #16a34a;
}
Try It Yourself

Browser Support

:placeholder-shown is a CSS selector.

✓ Selectors

:placeholder-shown

Supported in modern browsers.

94% Modern browsers
Google Chrome Recent
Full support
Mozilla Firefox Recent
Full support
Apple Safari Recent
Full support
Microsoft Edge Recent
Full support
:placeholder-shown Modern support

Bottom line: Safe for modern sites. Keep readable defaults without the selector.

Frequently Asked Questions

::placeholder styles the hint text. :placeholder-shown styles the control while that hint is visible.
It matches any empty placeholder-capable control, required or not.
Yes. Once the value is non-empty, :placeholder-shown no longer matches.
It is for inputs and textareas that show placeholder text.
Widely supported in modern browsers.

Next: :autofill

Continue with :autofill.

:autofill →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

2 people found this page helpful