Example A simple HTML form with two input fields and one submit button: <form action="form_action.asp" method=...
Example
A simple HTML form with two input fields and one submit button:<form action="form_action.asp" method="get"> First name: <input type="text" name="fname" /><br /> Last name: <input type="text" name="lname" /><br /> <input type="submit" value="Submit" /> </form> |
Definition and Usage
The <form> tag is used to create an HTML form for user input.A form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A forms can also contain select menus, textarea, fieldset, legend, and label elements.
Forms are used to pass data to a server.
Browser Support
The <form> tag is supported in all major browsers.Differences Between HTML and XHTML
NONETips and Notes
Note: Form is a block-level element, and creates a line break before and after itself.Required Attributes
DTD indicates in which DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.Attribute | Value | Description | DTD |
---|---|---|---|
action | URL | A URL that defines where to send the data when the submit button is pushed | STF |
Optional Attributes
Attribute | Value | Description | DTD |
---|---|---|---|
accept | list of content types | A comma separated list of content types that the server that processes this form will handle correctly | STF |
accept-charset | charset_list | A comma separated list of possible character sets for the form data. The default value is "unknown" | STF |
enctype | mimetype | The mime type used to encode the content of the form | STF |
method | get post | The HTTP method for sending data to the action URL. Default is get.method="get": This method sends the form contents in the URL: URL?name=value&name=value. Note: If the form values contains non-ASCII characters or exceeds 100 characters you MUST use method="post". method="post": This method sends the form contents in the body of the request. Note: Most browsers are unable to bookmark post requests. | STF |
name | form_name | Defines a unique name for the form | TF |
target | _blank _self _parent _top | Where to open the target URL.
| TF |