HTML form Attribute
Definition and Usage
The form attribute specifies one or more forms the element belongs to.
Applies to
The form attribute can be used on the following elements:
Elements | Attribute |
---|---|
<button> | form |
<fieldset> | form |
<input> | form |
<keygen> | form |
<label> | form |
<meter> | form |
<object> | form |
<output> | form |
<select> | form |
<textarea> | form |
Examples
Button Example
A button located outside a form (but still a part of the form):
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
</form>
<button type="submit" form="form1" value="Submit">Submit</button>
Fieldset Example
A <fieldset> element located outside a form (but still a part of the form):
What is your favorite color? <input type="text" name="fav-color"><br>
<input type="submit">
</form>
<fieldset form="form1">
Name: <input type="text" name="username"><br>
Email: <input type="text" name="usermail"><br>
</fieldset>
Input Example
An input field located outside the HTML form (but still a part of the form):
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
Last name: <input type="text" name="lname" form="form1">
Keygen Example
A <keygen> element located outside the form (but still a part of the form):
Username: <input type="text" name="usr_name">
<input type="submit">
</form>
Encryption: <keygen name="security" form="secureform">
Label Example
A <label> element located outside a form (but still a part of the form):
<input type="radio" name="gender" id="male" value="male"><br>
<label for="female">Female</label>
<input type="radio" name="gender" id="female" value="female"><br>
<label for="other">Other</label>
<input type="radio" name="gender" id="other" value="other"><br><br>
<input type="submit" value="Submit">
</form>
<label for="male" form="form1">Male</label>
Meter Example
A <meter> element located outside a form (but still a part of the form):
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
<meter form="form1" name="x1" min="0" low="40" high="90" max="100" value="95"></meter>
Object Example
An <object> element located outside a form (but still a part of the form):
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
<object data="helloworld.swf" height="400" width="400" form="form1" name="obj1"></object>
Output Example
An <output> element located outside a form (but still a part of the form):
oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
<input type="range" id="a" name="a" value="50">100
+<input type="number" id="b" name="b" value="50">
<br><br>
<input type="submit">
</form>
<output form="numform" name="x" for="a b"></output>
Select Example
A drop-down list located outside a form (but still a part of the form):
Firstname:<input type="text" name="fname">
<input type="submit">
</form>
<select name="carlist" form="carform">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
Textarea Example
A text area located outside a form (but still a part of the form):
Name: <input type="text" name="usrname">
<input type="submit">
</form>
<textarea name="comment" form="usrform">Enter text here...</textarea>
Browser Support
The form
attribute has the following browser support for each element:
Element | |||||
---|---|---|---|---|---|
button | 10.0 | Not supported | 4.0 | 5.1 | 9.5 |
fieldset | Not supported | Not supported | Not supported | Not supported | Not supported |
input | 9.0 | Not supported | 4.0 | 5.1 | 10.6 |
keygen | Yes | Not supported | Yes | 6.0 | Yes |
label | Yes | Yes | Yes | Yes | Yes |
meter | Not supported | Not supported | Not supported | Not supported | Not supported |
object | Not supported | Not supported | Not supported | Not supported | Not supported |
output | Yes | Not supported | Yes | Yes | Yes |
select | Yes | Not supported | Yes | Yes | Yes |
textarea | Yes | Not supported | Yes | Yes | Yes |