HTML <form> tag
The <form> tag is used to create a form. There are many elements you can have in a form including textboxes, textareas, buttons, drop down lists, checboxes, and radio buttons. Forms are the method by which data is sent from the user to the web server.
Attributes
| Attribute | Description | Possible values |
|---|---|---|
| action | Required. Specifies the URL where to send the form data | theURL |
| accept | Specifies a list of acceptable file types (set using MIME types) that can be uploaded through the form | mimeTypes |
| accept-charset | Specifies a list of possible character sets for the forms data that will be accepted by the server | theCharset |
| enctype | Sets how form data will be encoded | application/x-www-form-urlencoded (default), multipart/form-data (for uploading files), text/plain (convert spaces to the "+" character) |
| method | Method used to send form data | get, post |
| name | Name of the form | formName |
| target | Deprecated. Where the page will open when the form is submitted | _blank, _self, _parent, _top |
Standard attributes
accesskey, class, dir, id, lang, style, title, xml:lang
For more information on standard attributes, check out our HTML standard attributes reference page.
Event attributes
onclick, ondblclick, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onkeydown, onkeypress, onkeyup, onreset, onsubmit
For more information on event attributes, check out our HTML event attributes reference page.
Example
<form action="getData.php" name="mainForm" method="post">
First name: <input type="text" name="name" /><br />
Last name: <input type="text" name="lname" /><br />
E-mail: <input type="text" name="email" /><br />
<input type="submit" value="Submit" />
</form>
Output:
Tips & notes
To add emphasis to a form/make it more readable, add a fieldset and legend to it.