I have two problems with a form I am making, the first is the I want to throw some css onto a form. This works with my <textarea> box, as it has a closing tag and you can put the text in between. The <input> tags on the other hand have to get text trough the value="" tag, which doesn’t respond to any of my CSS tries.
Secondly, I was wondering if it is possible to make the box clear itsself once it is clicked. (not sure if HTML forms support that)
Here is a link to the form with the css, so you can see the problem. http://jsfiddle.net/D39rr/5/
You’re looking for the
placeholderattribute:JS Fiddle demo.
To style the
placeholdertext (in compliant browsers):JS Fiddle demo.
To style the text, whether it’s from the
valueattribute or user-entered, simply use the usualcolor,font-style,font-weight, etc:JS Fiddle demo.
Incidentally, the
textarea, as you correctly note, ‘has a closing tag.’ Therefore it’s not a self-closing (or void) element, and should not have a/character in its opening tag (as you do in your linked JS Fiddle:<textarea id="style" name="message" />Type out your question here</textarea>), instead it should be, simply:Or, with the
placeholder:It’s worth noting, also, that using the
placeholderto replace alabelmeans that any guidance offered is explicitly hidden once the user has focused, or entered data into, the field. If you don’t want thelabelelements visible all the time, then one way to show the guidance only while theinputis focused is:Which triggers the reveal once the
inputis focused/active: JS Fiddle demo.