I cannot figure out what is wrong with my markup, but the placeholder for the text area will not appear. It seems as though it may be covered up with some blank spaces and t
use <textarea></textarea>
instead of leaving a space between the opening and closing tags as <textarea>
</textarea>
Well, technically it does not have to be on the same line as long as there is no character between the ending ">" from start tag and the starting "<" from the closing tag. That is you need to end with
...></textarea>
as in the example below:
<p><label>Comments:<br>
<textarea id = "comments" rows = "4" cols = "36"
placeholder = "Enter comments here"
class = "valid"></textarea>
</label>
</p>
I know this post has been (very well) answered by Aquarelle but just in case somebody is having this issue with other tag forms with no text such as inputs i'll leave this here:
If you have an input in your form and placeholder is not showing because a white space at the beginning, this may be caused for you "value" attribute. In case you are using variables to fill the value of an input check that there are no white spaces between the commas and the variables.
example using twig for php framework symfony :
<input type="text" name="subject" value="{{ subject }}" placeholder="hello" /> <-- this is ok
<input type="text" name="subject" value" {{ subject }} " placeholder="hello" /> <-- this will not show placeholder
In this case the tag between {{ }} is the variable, just make sure you are not leaving spaces between the commas because white space is also a valid character.
So, the question now is how do we prefill the textarea element ? XYZ, you'll get:
The main problem is that in the textarea element we're unintentionally prefilling the element by white space.
its because there is a space somewhere. I was using jsfiddle and there was a space after the tag. After I deleted the space it started working
This one has always been a gotcha for me and many others. In short, the opening and closing tags for the <textarea>
element must be on the same line, otherwise a newline character occupies it. The placeholder will therefore not be displayed since the input area contains content (a newline character is, technically, valid content).
Good:
<textarea></textarea>
Bad:
<textarea>
</textarea>
This is not true anymore, according to the HTML5 parsing spec:
If the next token is a U+000A LINE FEED (LF) character token,
then ignore that token and move on to the next one. (Newlines
at the start of textarea elements are ignored as an authoring
convenience.)
You might still have trouble if you editor insists on ending lines with CRLF, though.