162

Why is there an element <textarea> instead of <input type="textarea">?

Yarin
  • 173,523
  • 149
  • 402
  • 512
Diogo Cardoso
  • 21,637
  • 26
  • 100
  • 138
  • 2
    There's by the way also an ``. The `` just represents a basic input element. The `type` attribute just represents the type of the value it holds. – BalusC May 30 '11 at 21:34

5 Answers5

177

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.

Marc Andreessen, 11 October 1993

Marcel
  • 27,922
  • 9
  • 70
  • 85
  • 20
    Yes, "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
    w3c is pretty consistent. this was before w3c – Mark Cidade Feb 13 '14 at 08:34
  • 11
    I 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
  • 2
    So 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
72

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>
Guillaume Esquevin
  • 2,992
  • 20
  • 25
51

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.

Mark Cidade
  • 98,437
  • 31
  • 224
  • 236
24

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.

Community
  • 1
  • 1
Izkata
  • 8,961
  • 2
  • 40
  • 50
7

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.

Community
  • 1
  • 1
Chas Latch
  • 79
  • 1
  • 2
  • 11
    This 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