I tried to follow the following topic, but unsuccessfully. Change an HTML5 input's placeholder color with CSS
I tried to colorize my placeholder, but it still stay grey on Chrome 17.0.963.56 m.
HTML
<input type='text' name='test' placeholder='colorize placeholder' value='' />
CSS
INPUT::-webkit-input-placeholder, INPUT:-moz-placeholder { color:red; } input[placeholder], [placeholder], *[placeholder] { color:green !important; }
JSfiddle
On Firefox 10.0.2, it works well.
In most browsers, the placeholder text is grey. To change this, style the placeholder with the non-standard ::placeholder selector. Note that Firefox adds a lower opacity to the placeholder, so we use opacity: 1 to fix this.
CSS ::placeholder Selector The placeholder text is set with the placeholder attribute, which specifies a hint that describes the expected value of an input field. Tip: The default color of the placeholder text is light grey in most browsers.
For Google Chrome Version 69: Open Inspect Elements: On Mac ⌘ + Shift + C, on Windows / Linux Ctrl + Shift + C OR F12.
Only the subset of CSS properties that apply to the ::first-line pseudo-element can be used in a rule using ::placeholder in its selector. Note: In most browsers, the appearance of placeholder text is a translucent or light gray color by default.
You forget a :
. Because of that, the whole selector got corrupted and didn't work. http://jsfiddle.net/a96f6/87/
Edit: Seems like (after an update?) this doesn't work anymore, try this:
input::-webkit-input-placeholder{ color:red; } input:-moz-placeholder { color:red; }
Note: don't mix the vendor prefix selectors (-moz, -webkit, -ms, ...). Chrome for example won't understand "-moz-" and then ignores the whole selector.
Edit for clarification: To make it work in all browsers, use this code:
::-webkit-input-placeholder { color:red; } ::-moz-placeholder { color:red; } ::-ms-placeholder { color:red; } ::placeholder { color:red; }
As @Alex said, for some reason you can't combine the selectors for multiple browsers.
This will work
::-webkit-input-placeholder { color:red; } ::-moz-placeholder { color:red; } ::-ms-placeholder { color:red; } ::placeholder { color:red; }
But this won't work (in Chrome at least):
::-webkit-input-placeholder, ::-moz-placeholder, ::-ms-placeholder, ::placeholder { color:red; }
Looks like a browser implementation quirk to me.
Also, note that you don't have to define placeholder styles globally, you can still scope the ::placeholder
selector just like you normally do. This works:
.my-form .input-text::-webkit-input-placeholder { color:red; } .my-form .input-text::-moz-placeholder { color:red; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With