Why is textarea seperate from input? Is it even necessary?

Why are input type=“text” and textarea elements separate at all? As they are both text input boxes, wouldn’t the textarea element just be a styled input type=“text”? Or is there another difference I’m not aware of yet?

In HTML5, the default type is text so we don’t need to declare a type if it is going to be text. Were we required to set this, then it would have to be applied to both input and textarea.elements.

Not sure I caught the complete gist of your question, so spur me along if this is not the answer you were looking for.

10 Likes

Thanks for your reply. I’m more wondering why the INPUT with type=text and TEXTAREA elements are separated at all, if TEXTAREA is only a larger version of INPUT type=text? Wouldn’t that be a styling difference, to be done in CSS, rather than a functional difference in HTML? Is there a functional difference between these 2 elements that I’m not realizing?

4 Likes

TEXTAREA allows line breaks, INPUT does not (I believe; correct me if I’m wrong).

As for the type, I’m not even sure we can declare a different type than ‘text’, or even need to in the older iterations of HTML. It’s defined as a text area.

Ideally, we squeeze as much functionality out of our HTML as possible, before introducing styles; and, we squeeze as much behavior out of our CSS as possible before introducing JavaScript.

When inputs are expected to be bits of data, then <input> and when expecting prose, <textarea>. HTML5 added a significant number of types to the input element. Be sure to look up these elements at w3.org or MDN.

19 Likes

Got it. Line breaks are the difference in functionality I wasn’t realizing, but do now. Thanks!

Other than ‘text’ as type options in an input tag, there are: ‘number’, ‘range’, ‘checkbox’, ‘radio’, etc… Then you have input lists and datalists, too.

5 Likes

Hi
When the textarea tag is closed inline (like this <textarea … />), the textarea contains html until the end of the document :slight_smile:
Strange.

TEXTAREA is not a void element, but a container for textual data.

<textarea>

</textarea>
1 Like

Hi, In order to give the default value to the textarea, we need to write the text in between the opening and closing tag, Why don’t we have a value attribute to add the default value just like we had in the input tag?

<input type="text" name="textbox" id="textbox" value="Enter a value">
1 Like

i find writing text between opening and closing tag of textarea more logical. I mean, you do the same for paragraph, span and many other elements

input is actually the odd one out, given <input> is self-closing, you can’t type text between the opening and closing tag, thus we need an attribute

3 Likes

oh Okay, makes sense. Thanks !

Why is it that the default value in the <textarea> element cannot be put in the “value” attribute like the <input> element?

I covered this in an earlier answer in this topic:

FAQ: Learn HTML: Forms - Textarea element

1 Like

The link doesn’t seem to lead anywhere for me.

The topics where split, this seems to be where my reply has gone:

Why is textarea seperate from input? Is it even necessary?