---
title: "How do I style placeholder text in an input?"
description: "Use the ::placeholder pseudo-element to change placeholder colour and font. Keep it readable, and never use a placeholder in place of a real label."
url: https://www.danny.engineering/answer/css/how-do-i-style-placeholder-text-in-an-input
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["CSS"]
---

# How do I style placeholder text in an input?

## The short answer


Select the placeholder with the `::placeholder` pseudo-element. It works on `input` and `textarea` elements. Keep the colour readable, and always give the field a real `label` as well.


```css
input::placeholder,
textarea::placeholder {
  color: #6b7280;
  font-style: italic;
  opacity: 1;
}
```


## Why it happens


The placeholder is not a child element you can select with a normal class. The browser draws it inside the field from the `placeholder` attribute, so CSS exposes it through a pseudo-element, the same way `::before` or `::selection` expose other parts of the page.


Only a subset of properties work inside `::placeholder`: the font properties, `color`, `opacity`, `letter-spacing`, `word-spacing`, `text-decoration`, `text-transform`, `line-height` and background properties, among a few others. Layout properties like `padding` and `margin` do not apply to it. To change spacing, style the input itself.


You may also see vendor prefixes such as `::-webkit-input-placeholder` in older code. They were needed many years ago. All current browsers support the unprefixed `::placeholder`, so you can drop them.


## How to fix it


### Style the placeholder


```css
.field {
  font: inherit;
  color: #111827;
  padding: 0.625rem 0.75rem;
  border: 1px solid #9ca3af;
  border-radius: 0.375rem;
}

.field::placeholder {
  color: #6b7280;
  opacity: 1;
}
```


Setting `opacity: 1` matters. Firefox has historically given placeholders a lower default opacity, so your chosen colour would come out paler than you intended. Set the colour you want and keep opacity at 1.


### Keep enough contrast


The Web Content Accessibility Guidelines (WCAG) ask for a contrast ratio of at least 4.5:1 for normal text. Placeholder text is still text people need to read, so aim for that ratio against the field background. Very light greys like `#ccc` on white fail it. A mid grey such as `#6b7280` on white passes.


In dark mode, set a separate value rather than reusing the light theme grey.


```css
@media (prefers-color-scheme: dark) {
  .field {
    background: #111827;
    color: #f9fafb;
  }

  .field::placeholder {
    color: #9ca3af;
  }
}
```


### Style the field while the placeholder is showing


`::placeholder` styles the text. To style the whole input while it is empty and showing its placeholder, use the `:placeholder-shown` pseudo-class.


```css
.field:placeholder-shown {
  border-style: dashed;
}

.field:not(:placeholder-shown):invalid {
  border-color: #b91c1c;
}
```


The second rule is a handy pattern: it only shows an invalid style once the person has typed something.


### Use a real label, not a placeholder


A placeholder disappears as soon as someone starts typing, so it cannot do the job of a label.


```html
<label for="email">Email address</label>
<input id="email" type="email" placeholder="name@example.com" autocomplete="email" />
```


Use the placeholder for a short example of the expected format, if anything. Put instructions that people need while typing in a hint below the field, linked with `aria-describedby`.


## Common pitfalls

- **Placeholder as the only label.** People forget what the field was for once they start typing, and screen readers do not reliably treat a placeholder as the field's name. Always add a `label`.
- **Text that looks filled in.** A dark placeholder can look like a real value, so people skip the field. Keep it clearly lighter than the input text, while still passing contrast.
- **Trying to pad the placeholder.** Padding on `::placeholder` does nothing. Add padding to the input.
- **Putting important instructions in it.** Password rules or date formats vanish on the first keystroke. Put them in visible helper text.
- **Selector lists with old prefixes.** If one selector in a list is invalid in a browser, the whole rule is dropped. Do not group old vendor-prefixed selectors with `::placeholder` in the same rule.

## Related reading

- [MDN: ::placeholder](https://developer.mozilla.org/en-US/docs/Web/CSS/::placeholder)
- [MDN: :placeholder-shown](https://developer.mozilla.org/en-US/docs/Web/CSS/:placeholder-shown)
