Coding CommunityE-Learning

Learn HTML-CSS: How To Change an Input’s HTML5 Placeholder Color with CSS?

html5 placeholder colorChanging the Input’s HTML5 Placeholder color with CSS can be challenging. The reason behind the complexity is how different browsers react with HTML5. The good news is that there is a working solution that you can use to make it happen. So, how to make it work?

First, you need to understand that two different implementations are in use. They are pseudo-classes and pseudo-elements.

Now, that you are aware of the types of implementation, let’s go through the code.

The above code will enable you to color the input’s HTML5 placeholder. For each browser, there is a different implementation. For example,

  1. Microsoft Edge, Blink, WebKit utilize the ::-webkit-input-placeholder pseudo-element.
  2. :-moz-placeholder is a pseudo-class and is used by Mozilla Firefox version 4 to 18.
  3. ::-moz-placeholder is a pseudo-element and works for Mozilla Firefox 19+.
  4. And lastly :-ms-input-placeholder is a pseudo-class for Internet Explorer 10 and 11.

All the above pseudo-classes and pseudo-elements are necessary to handle the required result.

Also, you need to make sure that the selectors are kept separately. The reason is simple: If any one of the selectors is invalid, it will make the group invalid as well, making your code unusable.

There are some special cases that you need to make sure don’t happen.

  1. Reduced opacity is seen in Firefox’s placeholder. To make sure it works, you need to put opacity:1 in your code.
  2. The placeholders should be tested for both size and font.

To understand the whole concept, you can watch it live here. The code is put together by Sk8erPeter.

Do you have anything to add to the tutorial? If yes, don’t forget to use the comments section below.

You can also check on our website for videos about HTML/CSS. Below are some examples:

  • improve web design: css, html (part 2) – HTML5

  • Coding while in class (part 1) – HTML5

You can also follow some of our broadcasters who program in JavaScript as below:

 continuitydrift

 Foxxel

Another cool way to find out interesting things about HTML/CSS is to access our project page!

About author

About Author Dr. Michael Jurgen Garbade is the founder of LiveEdu.TV, Kyuda, Education Ecosystem. He is future Venture Capitalist, Future Politician and always on the lookout for the Next Big Challenge. Obtained Masters in business administration and physics, and a Ph.D. in finance with professional work experience in high-paced environments at Fortune 500 companies like Amazon and General Electric. Expertize: Python, PHP, Sencha Touch & C++, SEO, Finance, Strategy & E-commerce. He speaks English and German and has worked in the US, Europe, and Asia. At Education Ecosystem he is the CEO and runs business operations.
Related posts
Career DevelopmentCybersecurity

Top 12 Free Projects to Become a Cybersecurity Expert in 2020

Career DevelopmentCoding Community

10 Python Projects to Learn from Home During Quarantine

Career DevelopmentData Science

Machine Learning Projects to Practice During Quarantine

Frontpage

Top 10 Web Development Frameworks of 2020