I've been wondering why none of the revisions to the HTML specification have ever made textarea
able to be self-closing. Lot's of SO questions have answered why it is a separate tag from input
, and it makes sense to me that they'd want to preserve it as a separate tag for compatibility, but why wouldn't they make <textarea />
just as valid as <textarea></textarea>
since this wouldn't break anything as far as I can tell.
The <textarea> tag defines a form field where user can input a multi-line text. Unlike the <input> tag, text wrapping inside <textarea> is allowed when the form is submitted. A text area can have an unlimited number of characters. The text within this tag is rendered in a fixed-width font (usually Courier).
For React, it's mostly a convention. One convention is to always use self-closing tags if there is no content ( children) inside of your component. So for a textarea it would be self closing.
That's because SCRIPT TAG is not a VOID ELEMENT. In an HTML Document - VOID ELEMENTS do not need a "closing tag" at all!
<textarea> is a replaced element — it has intrinsic dimensions, like a raster image. By default, its display value is inline-block .
Because <input />
can't work like container for text, While <textarea> text goes here</textarea>
can work as container for default text!
Here is what explain your curiosity about why they choose to go this way.
textarea {
width: 300px;
height: 100px;
}
<!-- Easy way for default input text -->
<textarea>Here is why because text can be input into box like paragraph tag</textarea>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With