HTML textarea Tag form Attribute Tutorial

In this section, we will learn what the form attribute is in HTML <textarea> and how to use it.

What is form Attribute in HTML <textarea> Tag?

Usually, the use of <textarea> element is within the body of a form in an HTML document.

But this is not always the case! Sometimes a <textarea> is created outside of any form field!

But at the end, the value of a <textarea> element should be submitted to a server via a form.

So, for those cases where we have a <textarea> element outside of any forms, in order to link that <textarea> to a form, we can use the `form` attribute.

This way, when that form is submitted to a server, the value of the target <textarea> element is also submitted to the server as well.

Note: you can use JavaScript to independently send the value of a <textarea> element to a server.

HTML form Attribute in <textarea> Tag Syntax:

<textarea form = “form-id”> </textarea>

<textarea> Tag form Attribute Values

The value we set for the form attribute is the value of the `id` attribute of the target form that we want this <textarea> element to be connected to.

For example, if the id value of the target form is set to “comment-form”, thus the value of the `form` attribute will be “comment-form” as well.

Example: using form attribute in HTML <textarea> tag

See the Pen using form attribute in HTML <textarea> tag by Omid Dehghan (@odehghan) on CodePen.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies