To change the color of a placeholder, you can use the ::placeholder
selector. However, it is not possible to change the color of just one letter in the placeholder.
If you want to customize the color of specific letters in a placeholder, you can create a custom input using HTML
and CSS
.
/**
* Here is a basic example of how you can customize your input using HTML and CSS.
*/
.input {
background-color: #fff;
border-radius: 3px;
position: relative;
display: inline-block;
border: 1px solid #888;
}
input {
background-color: transparent;
position: relative;
padding: 5px;
z-index: 1;
border: none;
}
.placeholder {
position: absolute;
color: #ccc;
left: 5px;
top: 50%;
transform: translateY(-50%)
}
/* Display an asterix when the input is required */
input:required + .placeholder::after {
content: "*";
color: red;
}
/* Hide the placeholder when the user starts typing */
input:focus + .placeholder {
visibility: hidden;
opacity: 0;
}
<div class="input">
<input type="text" name="name" required />
<span class="placeholder">Your name</span>
</div>
Instead of using the placeholder=""
attribute in your input
, you can place the text inside a custom span
element with the class name placeholder.
If the input
is marked as required, the CSS
will add an asterix to indicate the requirement.