Why would <textarea col="5" row="5" />
break my layout in my modern browser but not if I explicitly use a closing tag such as <textarea col="5" row="5" /></textarea>
?
This has been bothering me. Is it part of the standard somehow?

- 25,943
- 66
- 198
- 303
-
It would probably work if you served your page as XML. HTML doesn't have self-closing tags. – bfavaretto Jun 20 '12 at 01:35
-
1See also this answer: http://stackoverflow.com/a/70288/27862 – user123444555621 Jun 20 '12 at 03:33
2 Answers
Yes, it is part of the standard:
http://www.w3.org/TR/html401/interact/forms.html#h-17.7
17.7 The TEXTAREA element
<!ELEMENT TEXTAREA - - (#PCDATA) -- multi-line text field -->
<!ATTLIST TEXTAREA
%attrs; -- %coreattrs, %i18n, %events --
name CDATA #IMPLIED
rows NUMBER #REQUIRED
cols NUMBER #REQUIRED
disabled (disabled) #IMPLIED -- unavailable in this context --
readonly (readonly) #IMPLIED
tabindex NUMBER #IMPLIED -- position in tabbing order --
accesskey %Character; #IMPLIED -- accessibility key character --
onfocus %Script; #IMPLIED -- the element got the focus --
onblur %Script; #IMPLIED -- the element lost the focus --
onselect %Script; #IMPLIED -- some text was selected --
onchange %Script; #IMPLIED -- the element value was changed --
>
Start tag: required, End tag: required
Why it breaks is another different story altogether, browsers could also implement it such that it just creates an empty textarea
and not break. But since this is required by the standard, you should just follow it.
-- EDIT --
Also as per @Seth comment (thanks!), it doesn't have value
attribute, so initial values go inside the tags.

- 59,630
- 19
- 106
- 123
-
Also, obviously you're going to use the end tag because there is no `value` attribute thus any initial values you want to put inside the text area has nowhere else to go except between the opening and closing tag. – Seth Malaki Jun 20 '12 at 01:31
By HTML 4.01 rules, <textarea col="5" row="5" />
is equivalent to <textarea col="5" row="5">>
(making the >
a data character). No browser follows this rule, though. Validators do, but this is difficult to see directly. A long explanation: Empty elements in SGML, HTML, XML, and XHTML.
What browsers do in practice is that they just skip the /
as garbage. This, too, means that you have just a start tag, and the browser then tries to process subsequent characters as contents of textarea
, though it may stop this at some point. Depending on the context, the layout of the document may get messed up.
However, if the document is sent with an XML media type (in HTTP headers), it will be processed by XML rules, and then <textarea col="5" row="5" />
is equivalent to <textarea col="5" row="5"></textarea>
. Such usage is not recommended in XHTML when used on the Internet; see clause C.3 of the (in)famous appendix C of the XHTML 1.0 spec.

- 195,524
- 37
- 270
- 390