One possible option would be to use :valid pseudo-class for the required <input> to make the Absolutely Positioned sibling element disappear - which is used as a placeholder under the input.
So, we can use the ::before / ::after pseudo-elements over an absolutely positioned element to change the color of our pseudo-placeholder.
.input-wrapper { display: inline-block; position: relative; } .input-wrapper input { background: transparent; border: 1px solid #999; } .input-wrapper input:valid + .placeholder { display: none; } .input-wrapper .placeholder { position: absolute; top: 1px; left: 2px; z-index: -1; } .input-wrapper .placeholder::before { content: attr(data-placeholder); color: #999; } .input-wrapper .placeholder::after { content: " *"; color: tomato; }
<div class="input-wrapper"> <input id="firstName" name="fname" type="text" maxlength="50" required> <span class="placeholder" data-placeholder="First Name"></span> </div>
It is worth noting that IE10 + supports the pseudo-class :valid .
source share