6

Reading an article about HTML5, it occurs to me that while placeholders are incredibly useful in form usability, if they can not be targeted with CSS without javascript, they really are a baby step.

So can I target the placeholder in CSS to look differently from inputted text?

Mild Fuzz
  • 27,845
  • 29
  • 97
  • 148

2 Answers2

6

Webkit uses a ::-webkit-input-placeholder pseudoelement. Moz uses a :-moz-placeholder pseudoclass.

Lea Verou
  • 23,130
  • 9
  • 44
  • 47
2

enter image description here I assume you have got something like this in your HTML

<input type="text" name="name" />

The corresponding css would be

input::-webkit-input-placeholder { /* Chrome/Opera/Safari */
  color: blue;
}
input::-moz-placeholder { /* Firefox 19+ */
  color: blue;
}
input:-ms-input-placeholder { /* IE 10+ */
  color: blue;
}
input:-moz-placeholder { /* Firefox 18- */
  color: blue;
}
input:placeholder { 
  color: blue;
}

I also encourage you taking a look at

input:placeholder-shown {
  border: 5px solid red;
}

This is a good resource.

Mehdi Raash
  • 7,960
  • 1
  • 28
  • 41