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
Not sure I caught the complete gist of your question, so spur me along if this is not the answer you were looking for.
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?
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.
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.
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.
When the textarea tag is closed inline (like this <textarea … />), the textarea contains html until the end of the document
TEXTAREA is not a void element, but a container for textual data.
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">
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
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
I covered this in an earlier answer in this topic:
The link doesn’t seem to lead anywhere for me.
The topics where split, this seems to be where my reply has gone: