# :placeholder-shown

> The `:placeholder-shown` CSS pseudo-class applies to input elements when their placeholder text is visible in the UI.

## How do I check if an input is empty in CSS with :placeholder-shown?

The pseudo-class that selects input or textarea elements when their placeholder text is visible. It can be used to apply styles when the placeholder is present, such as adjusting the background color or adding a border to indicate that the field is empty.

- Topic: Pseudo Classes
- Type: pseudo-class
- Browser support: Chrome 47+, Chrome Android 47+, Edge 79+, Firefox 51+, Firefox Android 51+, Safari 9+, Safari iOS 9+

## Example

Wrong:

```css
input:empty + label {
  font-size: 0.75rem;
}
```

Right:

```css
input:not(:placeholder-shown) + label {
  font-size: 0.75rem;
}
```

`input:empty` always matches because inputs have no children; `:not(:placeholder-shown)` matches only once the field has a value.

## Common mistakes

- `:placeholder-shown` never matches because the input has no `placeholder` attribute.
- Confusing it with `::placeholder`, which styles the hint text, not the field.

## Key points

- The input has a `placeholder` attribute, even a single space, or `:placeholder-shown` never matches.
- Floating labels use a real `<label>`, not the placeholder as the only label.
- Styles for the hint text itself use `::placeholder`, not `:placeholder-shown`.

## Interview questions

### What is the difference between :placeholder-shown and ::placeholder?

`:placeholder-shown` selects the input while its hint is visible. `::placeholder` styles the hint text itself.

### Can I use :placeholder-shown without a visible placeholder?

Yes. Set `placeholder=' '` with a single space, and the pseudo-class still matches while the field is empty.

## Related cards

- [::placeholder](https://wonderium.dev/css/placeholder.md)
- [`<input>`](https://wonderium.dev/html/input.md)
- [`<label>`](https://wonderium.dev/html/label.md)
- [:not()](https://wonderium.dev/css/not.md)
- [Accessible Forms](https://wonderium.dev/a11y/accessible-forms.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/placeholder-shown
- Last updated: 2026-11-25
