Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing an input's HTML5 placeholder color with CSS does not work on Chrome

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

  • http://jsfiddle.net/F4xfV/1/

On Firefox 10.0.2, it works well.

like image 695
el-teedee Avatar asked Feb 26 '12 09:02

el-teedee


People also ask

Is it possible to change the color in an html5 input placeholder?

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.

What is placeholder color CSS?

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.

How do I inspect a placeholder in Chrome?

For Google Chrome Version 69: Open Inspect Elements: On Mac ⌘ + Shift + C, on Windows / Linux Ctrl + Shift + C OR F12.

Can I use placeholder CSS?

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.


2 Answers

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; } 

like image 70
Alex Avatar answered Sep 24 '22 07:09

Alex


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; } 
like image 27
Dmitry Pashkevich Avatar answered Sep 21 '22 07:09

Dmitry Pashkevich