You can use the ::placeholder pseudo-element in CSS to target the placeholder text of an HTML5 input and change its color.
Here is an example of how you can change the placeholder color to red:
input::placeholder {
color: red;
}
You can also use other CSS properties like font-size, font-family, etc.
input::placeholder {
color: red;
font-size: 16px;
font-family: Arial, sans-serif;
}
You can also target specific input using id or class
<input type="text" id="username" placeholder="Username">
Copy code
#username::placeholder {
color: red;
}
<input class="myclass" type="text" placeholder="Username">
Copy code
.myclass::placeholder {
color: red;
}
Please note that this will only work in modern browsers that support the ::placeholder pseudo-element, so you may need to provide a fallback solution for older browsers.
Comments (0)