{"id":9339,"date":"2021-01-05T08:34:43","date_gmt":"2021-01-05T13:34:43","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=9339"},"modified":"2021-12-04T06:46:02","modified_gmt":"2021-12-04T06:46:02","slug":"change-html5-input-placeholder-color-css","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/change-html5-input-placeholder-color-css\/","title":{"rendered":"How to Change an HTML5 Input’s Placeholder Color With CSS"},"content":{"rendered":"\n
Yes, there is a way to change the color of the placeholder text in your HTML5<\/a> form inputs. This can be done by using the ::placeholder<\/strong><\/em> pseudo-element.<\/p>\n\n\n\n You would generally use it like so:<\/p>\n\n\n\n <\/p>\n\n\n\n For backward compatibility, it is good to know that there are some caveats to be aware of.<\/p>\n\n\n\n Seeing User agents are required to ignore a rule with an unknown selector, web developers must separate the rules for each browser otherwise the whole group would be ignored by all browsers. See this example:<\/p>\n\n\n\n <\/p>\n\n\n\n Note above that the rules for Firefox include opacity. This is because Firefox’s placeholder appears to be showing with reduced opacity, so needs we need to use opacity: 1<\/strong><\/em> here to control it.<\/p>\n\n\n\n Here is an example of the HTML input affected by the CSS<\/a> rules above used to change the placeholder color.<\/p>\n\n\n\n::placeholder { \/* Most modern browsers support this *\/\n color: #a9a9a9;\n}<\/code><\/pre>\n\n\n\n
::-webkit-input-placeholder { \/* WebKit, Blink, Edge *\/\ncolor: #a9a9a9;\n}\n\n:-moz-placeholder { \/* Mozilla Firefox 4 to 18 *\/\ncolor: #a9a9a9;\nopacity: 1;\n}\n\n::-moz-placeholder { \/* Mozilla Firefox 19+ *\/\ncolor: #a9a9a9;\nopacity: 1;\n}\n\n:-ms-input-placeholder { \/* Internet Explorer 10-11 *\/\ncolor: #a9a9a9;\n}\n\n::-ms-input-placeholder { \/* Microsoft Edge *\/\ncolor: #a9a9a9;\n}\n\n::placeholder { \/* Most modern browsers support this. *\/\ncolor: #a9a9a9;\n}<\/code><\/pre>\n\n\n\n
<input type="text" placeholder="The cool placeholder!"><\/code><\/pre>\n\n\n\n