::placeholder

Term side of the Card.
Topic: Pseudo Elements
Unit title: ::placeholder
Categories: Pseudo-element
Explanation side of the Card

Explanation: The pseudo-element used to style the placeholder text within an input or textarea element. It allows changing the appearance of the placeholder, such as its color, font or opacity, without affecting the input text itself.

Browser compatibility:
  • The chrome browser supports this feature starting from version 57.
  • The edge browser supports this feature starting from version 79.
  • The firefox browser supports this feature starting from version 51.
  • The safari browser supports this feature starting from version 10.1.
Availability: 

Example

Wrongcss
input::placeholder {
  color: #ccc;
}
Rightcss
input::placeholder {
  color: #6b6b6b;
}

#6b6b6b stays readable on a white field, while #ccc is too faint for many users.

Common mistakes

  • Using the placeholder as the only label, so it disappears once the user types.
  • Light gray placeholder text that fails contrast checks.

Key points

  • Placeholder text keeps enough contrast with the field background.
  • Fields have a real <label>; the placeholder isn't the only label.
  • Only text styles are set on ::placeholder, as box properties like margin are ignored.

Interview questions

Why shouldn't the placeholder replace a label?

It disappears when the user types, is often low contrast and is not a reliable label. Use a visible <label> and keep the placeholder for an example value.

Which properties work on ::placeholder?

Text and background styles, such as color, font, opacity, letter-spacing and background-color. Box properties like margin and padding do not apply.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy