Forms & Inputs
HTML <form> Tag
The <form> tag is used to create an HTML form for user input.
Definition and Usage
The <form> tag is used to create an HTML form for user input.
Standard Syntax:
<form>...</form>Interactive ExampleRunnable
HTML <form> Example
htmlLive code demonstration for the <form> tag. Click "Try it Yourself" to edit and experiment in real time.
<div style="font-family: system-ui, sans-serif; padding: 16px; background: #ffffff; border-radius: 8px; border: 1px solid #e2e8f0; color: #0f172a;">
<form
action="/action_page.php"
method="get">
<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"><br><br>
<input
type="submit" value="Submit">
</form>
</div>Attributes for <form>
9 Supported Attributes| Attribute | Values | Default | Description |
|---|---|---|---|
| accept-charset | character_set | none | Specifies the character encodings that are to be used for the form submission |
| action | URL | none | Specifies where to send the form-data when a form is submitted |
| autocomplete | onoff | none | Specifies whether a form should have autocomplete on or off |
| enctype | application/x-www-form-urlencoded multipart/form-data text/plain | none | Specifies how the form-data should be encoded when submitting it to the server (only for method="post") |
| method | dialogget post | none | Specifies the HTTP method to use when sending form-data |
| name | text | none | Specifies the name of a form |
| novalidate | novalidate | none | Specifies that the form should not be validated when submitted |
| rel | externalhelplicensenextnofollownoopener noreferreropenerprevsearch | none | Specifies the relationship between a linked resource and the current document |
| target | _blank _self _parent _top | none | Specifies where to display the response that is received after submitting the form |
Global Attributes
The <form> tag also supports the standard global attributes in HTML, including class, id, style, title, hidden, and data-*.
Event Attributes
The <form> tag supports event attributes in HTML, such as onclick, onmouseover, onfocus, and more.
Browser Compatibility
ChromeEdgeFirefoxSafariOpera
More Tags in Forms & Inputs
View All 123Tags →<button>The <button> tag defines a clickable button.<datalist>The <datalist> tag specifies a list of pre-defined options for an <input> element.<fieldset>The <fieldset> tag is used to group related elements in a form.<input>The <input> tag specifies an input field where the user can enter data.<label>The <label> tag defines a label for several elements:<legend>The <legend> tag defines a caption for the <fieldset> element.