Advertisement
Home Open Editor ❯

HTML form Attribute

Example

<form action="action.php" method="get" id="formId">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname">
</form>

<button type="submit" form="formId" value="Submit">Submit</button>

Try this code ❯

Meaning

The form attribute should be set to a string that corresponds to the id of the form element is associated with.


Standard Syntax

<element form="formId">


Applies to:

The form attribute can be used on the following element:


Advertisement

Attribute Values

Value Description
formId The value of this attribute must be the id attribute of a <form> element in the same document.

More Examples

Example

<form action="action.php" method="get" id="form1">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname" form="form1"><br>
  <input type="submit">
</form>

<fieldset form="form1">
  <legend>User info:</legend>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname" form="form1">
</fieldset>

Try this code ❯


Example

<form action="action.php" id="form1">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <input type="submit" value="Submit">
</form>

<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" form="form1">

Try this code ❯


Example

<form action="action.php" id="form1">
  First name: <input type="text" name="fname"><br>
  <input type="submit" value="Submit">
</form>

<label for="anna">Your score:</label>
<meter id="anna" form="form1" name="anna" min="0" low="40" high="95" max="100" value="80"></meter>

Try this code ❯


Example

<form action="action.php" id="object1">
  First name: <input type="text" name="fname"><br>
  <input type="submit" value="Submit">
</form>

<object form="object1" data="demo/image.jpg" width="300" height="150"></object>

Try this code ❯


Example

<form id="form1" oninput="result.value=parseInt(a.value)+parseInt(b.value)">
  <input type="range" id="b" name="b" value="50" /> +
  <input type="number" id="a" name="a" value="10" />
  <input type="submit">
</form>
=
<output form="form1" name="result" for="a b">50</output>

Try this code ❯


Example

<form action="action.php" id="langform">
  <input type="submit">
</form>

<label for="lang">Choose your option:</label>
<select name="language" form="langform" id="lang">
  <option value="HTML">HTML</option>
  <option value="CSS">CSS</option>
  <option value="JavaScript">JavaScript</option>
</select>

Try this code ❯


Example

<form action="action.php" id="form1">
  <input type="submit" value="Submit">
</form>

<br><br>

<label for="demo">textarea demo:</label>
<textarea form="form1" id="demo" name="textareaText">
Hello world!
</textarea>

Try this code ❯

Home Open Editor ❯
Advertisement