In this section, we will learn what form attribute is and how to use it.
What is form Attribute in HTML <input> Tag?
Typically, when working with <input> elements, we tend to put them in the body of a <form> element to specify that the target input element belongs to that form.
But if the target element is outside the body of a form and still we want the input element to be part of that form, we can use the form attribute to link the input to the target form element.
The form attribute takes one value and that is the id of the target form. After that, this input element becomes part of the target form and when the form is submitted, the data of the input element will be submitted as well.
HTML form Attribute in <input> Tag Syntax:
<input type = “type” form = “form_id”>
<input> Tag form Attribute Values
The value of the form attribute is the value of the id attribute of the target form element.
Example: using form attribute in HTML <input> tag
See the Pen using form attribute in HTML <input> tag by Omid Dehghan (@odehghan) on CodePen.