0

I know it's possible to style the placeholder of an HTML element using the ::placeholder CSS pseudo-element.

E.g.

input[type="text"]::placeholder {
 ... /* style rules */
}

But is it possible to set the text of the placeholder in CSS?

input[type="text"]::placeholder {
 content: "Common placeholder for all inputs" /* content rules */
}
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336

2 Answers2

1

No.

content is intended to be used with pseudo-elements before & after.

ref: https://developer.mozilla.org/en-US/docs/Web/CSS/content

is there some particular reason why you'd want to have it set through css and not through html/javascript?

dee zg
  • 13,793
  • 10
  • 42
  • 82
-2

I would suggest you use Javascript for this with jQuery:

$('#search-input').attr('placeholder', 'Search for Stuff');

or pure javascript:

document.getElementById('search-input').setAttribute('placeholder', 'Search for Stuff');
Rumplin
  • 2,703
  • 21
  • 45
  • I wonder what is the reason for someone to give a negative vote on this anwser? Please elaborate. – Rumplin Jul 08 '19 at 07:05
  • you probably missed the *with CSS* – Temani Afif Jul 08 '19 at 09:05
  • I didn't miss that part, I just suggested to use javascript, because it's most probabl not doable with CSS and I don't think it's recommended to use CSS for content manipulation. – Rumplin Jul 09 '19 at 12:19