Why is there an element <textarea>
instead of <input type="textarea">
?
5 Answers
Maybe this is going a bit too far back but…
Also, I’d like to suggest that multiline text fields have a different type (e.g. “textarea") than single-line fields ("text"), as they really are different types of things, and imply different issues (semantics) for client-side handling.

- 27,922
- 9
- 70
- 85
-
20Yes, "different type", couldn't the same have been achieved via blah blah \n \n blah ? Why a distinct tag? – Serhiy Apr 03 '12 at 17:42
-
1@Serhiy I agree, it doesn't make much sense to introduce a new element for that (just like password doesn't have its own element). Unfortunately W3C isn't always consistent. – bart May 13 '13 at 21:19
-
8
-
11I wonder how this got this much upvote. The question is not about the difference between 'text' and 'textarea', but the reason for including the multi-line text as – Foreever Mar 12 '14 at 12:28
-
8@Foreever this is about as direct an answer as it gets. The reason there is a `textarea` element is because Marc Andreessen proposed it back in October 1993 for the reasons as quoted above. – Marcel Sep 09 '14 at 08:26
-
6@Marcel Marc Andreessen suggested that there should be a different **type** not **tag**. There are different types of input denoted by different values of `type` attribute of `input` tag and they all share one and the same `input` tag. So no, this quote is not an answer to this question. – Piotr Dobrogost Dec 10 '15 at 15:34
-
2@PiotrDobrogost [here's another post](http://1997.webhistory.org/www.lists/www-talk.1993q4/0179.html) later that same day where he says *"multiline texts fields should have a different **name**"*. It appears terminology wasn't being used as precisely as you'd think at this point in time so it isn't easy to tell either way whether he is referring to a new tag or type value. My previous comment also still stands. – Marcel Aug 02 '16 at 00:19
-
I think this answer should call out the obvious: It was a mistake. His reasoning makes no sense. – usr Apr 05 '17 at 13:49
-
2So checkbox is the same as text input, but single-line text input is something totally different than multi-line one... – Mariusz Jamro Jan 21 '18 at 19:47
So that its value can easily contain quotes and <> characters and respect whitespace and newlines.
The following HTML code successfully pass the w3c validator and displays <,> and & without the need to encode them. It also respects the white spaces.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Yes I can</title>
</head>
<body>
<textarea name="test">
I can put < and > and & signs in
my textarea without any problems.
</textarea>
</body>
</html>

- 2,992
- 20
- 25
-
16
-
9Textarea elements are not defined as containing CDATA, you still need to use entities for `<`, `&`, etc. It is just so it can handle whitespace. – Quentin Apr 12 '11 at 15:04
-
I just tested it and yes, you can put unencoded <, > and & within a textarea. And it successfully pass the w3c validator. – Guillaume Esquevin Apr 12 '11 at 17:18
-
That's definitely possible :/ I think @Marcel has the proper answer. – Guillaume Esquevin Nov 13 '12 at 14:52
-
2There's not one proper answer here. As with life in general (i.e., outside a box) there are multiple reasons for something being the way it is. – JohnK Mar 06 '13 at 15:26
-
well clearly if you put in there it wouldn't work so yes, you need to escape everything inside the `textarea` element anyway. – Matthew Jan 11 '16 at 18:54
A textarea
can contain multiple lines of text, so one wouldn't be able to pre-populate it using a value
attribute.
Similarly, the select
element needs to be its own element to accommodate option
sub-elements.

- 98,437
- 31
- 224
- 236
-
1Why wouldn't one be able to populate it with the `value` attr? Overflow wraps to the next line on resize of the `textarea` anyway. – OJFord Aug 17 '14 at 14:29
-
4
It was a limitation of the technology at the time it was created. My answer copied over from Programmers.SE:
From one of the original HTML drafts:
NOTE: In the initial design for forms, multi-line text fields were supported by the Input element with TYPE=TEXT. Unfortunately, this causes problems for fields with long text values. SGML's default (Reference Quantity Set) limits the length of attribute literals to only 240 characters. The HTML 2.0 SGML declaration increases the limit to 1024 characters.
I realize this is an older post, but thought this might be helpful to anyone wondering the same question:
While the previous answers are no doubt valid, there is a more simple reason for the distinction between textarea and input.
As mentioned previously, HTML is used to describe and give as much semantic structure to web content as possible, including input forms. A textarea may be used for input, however a textarea can also be marked as read only via the readonly attribute. The existence of such an attribute would not make any sense for an input type, and thus the distinction.

- 1
- 1

- 79
- 1
- 2
-
11This sounds reasonable, except that `input[type="text"]` can take the *readonly* attribute too. Which is sort of odd, now that you point it out! http://www.w3.org/TR/html-markup/input.text.html#input.text.attrs.readonly – Matt Jul 10 '14 at 21:29