Re: Styling HTML placeholder attribute

On Jan 24, 2013, at 12:05 PM, Philip Walton <philip@philipwalton.com> wrote:

> Obviously it would be terribly confusing, but has the option of both pseudo-class and pseudo-element been discussed?
> 
> `input:placeholder` would be used to describe an input element whose placeholder is visible and `input::placeholder` would be used to style the placeholder.

I agree with Sylvain that the name is what is leading to thinking about placeholder as an element-like thing that can be hidden or shown, when really it is just a state that causes the text in the box to be something that was not in the starting 'value' attribute and not typed by the user. To select it, you'd have to wrap that range of text in some sort of span and then hide it when the state changed due to typing or pasting, and that just seems like an unnecessary extra step that complicates the simple model of an input with some text in it. . 


> The spec specifically defines placeholders as only existing when there is no text in the input,

Which spec?

> but in my mind I've always wanted placeholders to double as type-ahead hint text as well.
> 
> If something like this were ever allowed in the future (input text and placeholder text being shown at the same time) then the color property of `input:placeholder` clearly couldn't apply to the placeholder text. It seems like using the color property to refer to both is limiting.

It's an interesting idea, but I don't think type-ahead text is the same thing as placeholder text. Having a second "thing" in the field that is a different color (and perhaps background-color) than other text in the field does imply a separate inline pseudo-element, so you would need something like '::text-suggestion' or something. Anyway, you wouldn't necessarily want it to be the same color as the placeholder text, either. 

Received on Thursday, 24 January 2013 20:50:10 UTC