HTML and CSS - Styling default values in form inputs


Hello, I know that this is a very specific question, but I’d like to know.

In the third section of the HTML course, I learned about creating forms with for example empty text inputs. I was taught that you could add default values that instruct users what to fill in or give examples, of which the syntax would look like this:


I would like to know how I should apply CSS on specifically this value attribute. For example, it would be great to have a lower opacity on the default value, but this should not appear on the text which a user fills in.

Thank you in advance!

Kind regards,


Hello and welcome on the forums. :grinning:

There is a way in HTML too, the placeholder attribute.
For example:

<input id="username" name="username" type="username" placeholder="username...">

Which appears like:
but when you start typing it disappears:

You can set its color, text-align and other CSS properties too with:

#username[placeholder] {
  color: green;
  text-align: center;

But most properties will effect writing:

By the way here’s the code if you need it.

Hope this helps :grinning: