1

Possible Duplicate:
HTML5 placeholder disappears on focus

In Safari and Chrome on Mac, when a user focuses on a text field with a placeholder attribute the placeholder will remain until a character is entered. In Firefox (and probably some other browsers too), the placeholder will disappear immediately upon the text field's selection. Is there any way to force Firefox and other browsers to keep the placeholder until the user starts typing like Chrome and Safari? Thanks!

Community
  • 1
  • 1
Gus
  • 1,905
  • 6
  • 23
  • 37
  • In that, a jQuery plugin is explicitly asked for. I am wondering if there is a style or attribute that can be applied that can fix this in some browsers without JS. – Gus Feb 03 '13 at 09:00
  • I think it is rather clear that there is no HTML or CSS tool for this. – Jukka K. Korpela Feb 03 '13 at 09:56
  • Placeholder styling. In FF, for example, -moz-placeholder allows you to style the placeholder. The browser may set the placeholder to not visible, and there may be a way to prevent that until the field updates. But this doesn't seem to work for me, so it might be possible that the browser does something else that is adjustable through CSS, etc. – Gus Feb 03 '13 at 19:17

1 Answers1

0

The behavior you're describing, from what I gather, is what we should be seeing browsers exhibit.

Here's what the spec says:

User agents should present this hint to the user, after having stripped line breaks from it, when the element's value is the empty string or the control is not focused (or both), e.g. by displaying it inside a blank unfocused control and hiding it otherwise.

Unfortunately, it doesn't seem as though they all conform to the spec (or the "or's" are vague enough that it was misinterpreted). There may be alternatives for browsers that you can experiment with (-moz-placeholder), but the placeholder attribute probably can't be forced to behave in a particular way.

RevanthKrishnaKumar V.
  • 1,855
  • 1
  • 21
  • 34
Nirvana Tikku
  • 4,105
  • 1
  • 20
  • 28
  • The “spec” (WHATWG page) cited is rather ambiguous and seems to say that the browser could, and maybe should, display the placeholder even actual data has been entered and the field has lost focus. This can hardly be the intent. – Jukka K. Korpela Feb 03 '13 at 08:39
  • Yes, it seems to me like having the placeholder stay until a character is entered is superior in user experience. – Gus Feb 03 '13 at 09:00
  • BTW, the recent versions of FF and IE Edge display the placeholder even when the element is focused. – Monsignor Nov 19 '15 at 10:22