Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

::placeholder — styling placeholder text

The ::placeholder pseudo-element selects hint text in a form field, not the field itself or its entered value. It lets you change the hint’s appearance independently of user-entered text.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

selector::placeholder { color: #595959; }

::placeholder represents displayed placeholder text in an input or textarea. It does not create that content; the example supplies it through the placeholder attribute.

Distinguish it from :placeholder-shown: that pseudo-class selects the whole field displaying a hint, whereas the pseudo-element selects the hint itself.

Styling is restricted: properties supported by ::first-line apply, except properties from CSS Inline Layout. Do not treat it as an arbitrary layout container. The example changes the hint’s color without changing the entered value’s color.

The hint often disappears after text is entered, but the specification leaves details to the browser. Keep a separate field label instead of relying solely on the hint. The example requires local verification; it does not establish compatibility across all browsers.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Placeholder styling</title>
<style>
  input {
    color: #111111;
    background: #ffffff;
    font: 16px sans-serif;
  }
  input::placeholder {
    color: #595959;
    opacity: 1;
  }
</style>
<label for="city">City</label>
<input id="city" type="text" placeholder="e.g. Warsaw">
</html>

Result

Initially: City — [e.g. Warsaw]. The hint is #595959 on white. After entering Warsaw, the value is #111111.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources