CSS Portal

::placeholder CSS Pseudo Element

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The ::placeholder pseudo-element in CSS is used to style the placeholder text of an input field or a textarea element. Placeholder text is the faint text displayed inside a form control before the user enters a value, typically serving as a hint or description of the expected input. Unlike normal text within the element, the placeholder text does not become part of the value of the input, and it disappears as soon as the user starts typing. This pseudo-element allows designers to customize its appearance independently from the content entered by the user.

Styling the ::placeholder pseudo-element can involve several CSS properties. Commonly, color is used to change the text color, while font-style and font-weight can adjust the typography. Additionally, opacity can control how faint or prominent the placeholder appears, giving subtle visual cues to users. It is important to note that some properties, such as background or padding, generally have no effect on the placeholder text.

The ::placeholder pseudo-element is widely supported across modern browsers, though certain older versions may require vendor prefixes like ::-webkit-input-placeholder or ::-moz-placeholder. Developers should also consider accessibility, ensuring that placeholder text is not the sole method of conveying important instructions, as its low contrast or disappearing nature can affect usability for some users.

Here is a simple example demonstrating its use:

<input type="text" placeholder="Enter your name">
input::placeholder {
  color: #888;
  font-style: italic;
  opacity: 0.7;
}

In this example, the placeholder text "Enter your name" will appear in a soft gray color, italicized, and slightly transparent, providing a visual cue without overpowering the main content entered by the user. The ::placeholder pseudo-element can be combined with other selectors, such as input types or classes, to achieve targeted styling for different form controls.

Syntax

::placeholder {
  /* ... */
}

Example

<body>

<form>
<label for="email">Newsletter Signup:</label>
<input type="email" id="email" placeholder="Enter your email address...">
</form>

</body>
/* Styling the actual input box for context */
input {
padding: 12px;
border: 2px solid #ccc;
border-radius: 5px;
width: 300px;
font-size: 16px;
}

/* Targeting the placeholder text specifically */
input::placeholder {
color: #e67e22; /* Changes text color to orange */
font-style: italic; /* Makes text italic */
font-weight: 300; /* Makes text thinner */
opacity: 1; /* Firefox requires this to display full color */
}

Browser Support

The following information will show you the current browser support for the CSS ::placeholder pseudo element. Hover over a browser icon to see the version that first introduced support for this CSS psuedo element.

This psuedo element is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 31st December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!