html tutorial - form Attribute in HTML - html5 - html code - html form

Learn html - html tutorial - form attribute in html- html examples - html programs
- The form attribute specifies the element belongs to one or more forms.
- The owner of the element will indicate the form.
Syntax for form attribute in HTML:
<element form="form_id">
Differences between HTML 4.01 and HTML5 for form attribute:
HTML 4.01
- The form attribute does not support in HTML4.
HTML 5
- HTML5 support form attribute.
Applies To:
Elements | Attribute |
---|---|
<button> | form |
<fieldset> | form |
<input> | form |
<keygen> | form |
<label> | form |
<meter> | form |
<object> | form |
<output> | form |
<select> | form |
<textarea> | form |
Attribute Values:
Value | Description |
---|---|
form_id |
Sample Coding for form Attribute in HTML:
Tryit<!DOCTYPE html>
<html>
<head>
<title>Wikitechy form attribute</title>
</head>
<body>
<form action="form.html" id="form_1">
Firstname:<input type="text" name="fname"> <br>
<input type="submit" value="Submit">
</form>
<p>Lastname:<input type="text" name="lname" form="form_1">
</p>
</body>
</html>
Code Explanation for form Attribute in HTML:

- The <form> tag is used to define a form with input elements.
- Id attribute is used to define the <form> tag id as “form_1”.
- The form attribute is used to append the <inputt> tag to the form which has the id attribute as “form_1”.
- The type=”submit”is used to submit the form-data When the user click the submit button.
Output for form Attribute in HTML:

- The Firstname text box is used to type a person’s first name.
- The submit button, is used to submit the person’s name to the form.
- The Lastname text box is used to type a person’s last name.
- When the user c <form> tag but that will be also submitted because of “form” attribute.

Browser Support for form Attribute in HTML:
Elements | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
button | 10 | No | 4 | 5.1 | 9.5 |
fieldset | No | No | No | No | No |
input | 9 | No | 4 | 5.1 | 10.6 |
keygen | Yes | No | Yes | 6 | Yes |
label | Yes | Yes | Yes | Yes | Yes |
meter | No | No | No | No | No |
object | No | No | No | No | No |
output | Yes | Yes | Yes | Yes | Yes |
select | Yes | No | Yes | Yes | Yes |
textarea | Yes | No | Yes | Yes | Yes |