Friday, May 15, 2009

Unneeded white space in textarea

I noticed an annoying behavior of textarea elements that have white space between the opening and closing tags. That space shows up as the initial value of that element in the browser. 

I've been using an edit control built on top of a textarea for a recent project and I noticed that upon clicking on the control to get focus, the caret cursor would not land in the top let corner of the control, instead it would have a few characters of left padding. 

That's because my Komodo Edit IDE was formatting the code by putting the end tag on a different line and would add sufficient white space for a balanced indentation. That was causing the padding to appear. 

The workaround is to keep the textarea element with a truly empty value like this:

No comments: