E-Learning

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

Changing 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.

::-webkit-input-placeholder { /* WebKit, Blink, Edge */ color: #0000ff; }

:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color: #0000ff; opacity: 1; }

::-moz-placeholder { /* Mozilla Firefox 19+ */ color: #0000ff; opacity: 1; }

:-ms-input-placeholder { /* Internet Explorer 10-11 */ color: #0000ff; }

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!

Dr. Michael J. Garbade

I, Dr. Michael J. Garbade is the co-founder of the Education Ecosystem (aka LiveEdu), ex-Amazon, GE, Rebate Networks, Y-combinator. Python, Django, and DevOps Engineer. Serial Entrepreneur. Experienced in raising venture funding. I speak English and German as mother tongues. I have a Masters in Business Administration and Physics, and a Ph.D. in Venture Capital Financing. Currently, I am the Project Lead on the community project -Nationalcoronalvirus Hotline I write subject matter expert technical and business articles in leading blogs like Opensource.com, Dzone.com, Cybrary, Businessinsider, Entrepreneur.com, TechinAsia, Coindesk, and Cointelegraph. I am a frequent speaker and panelist at tech and blockchain conferences around the globe. I serve as a start-up mentor at Axel Springer Accelerator, NY Edtech Accelerator, Seedstars, and Learnlaunch Accelerator. I love hackathons and often serve as a technical judge on hackathon panels.

View Comments

  • Working with HTML5 placeholders is not easy at all. There are different implementation for different browsers which makes life of web developers harder as usual. Great guide, btw!

Recent Posts

Blockchain in Elections: A Leap Toward Transparent Democracy

In 2024 we're witnessing a critical point in democratic technology: the integration of blockchain and…

3 weeks ago

Win Big with Our Amazon Fire Max 11 & AirPods Pro Giveaway!

We’re thrilled to announce an exciting opportunity for you to win not one but two…

2 months ago

Unleashing Potential: How Education Ecosystem Transforms Learning into Real-World Success

Acquiring practical skills is crucial for career advancement and personal growth. Education Ecosystem stands out…

4 months ago

The Role of Artificial Intelligence in Modern Software Development

Artificial Intelligence (AI) has been making significant strides in various industries, and the software development…

7 months ago

Highest Stable Coin Yields – (W16 – 2024)

Another week to bring you the top yield platforms for three of the most prominent…

8 months ago

LEDU Token OTC Trading

If you hold a large volume of LEDU tokens above 1 million units and wish…

9 months ago