Breaking

Thursday, May 9, 2019

HTML form Tag

Example

An HTML form with two input fields and one submit button:
<form action="/action_page.php"method="get">
  First name: <input type="text"name="fname"><br>
  Last name: <input type="text"name="lname"><br>
  <input type="submit"value="Submit">
</form>
Try it Yourself »
More "Try it Yourself" examples below.

Definition and Usage

The <form> tag is used to create an HTML form for user input.
The <form> element can contain one or more of the following form elements:

Browser Support

Element
<form>YesYesYesYesYes

Differences Between HTML 4.01 and HTML5

HTML5 has added two new attributes: autocomplete and novalidate, and removed the accept attribute.


Differences Between HTML and XHTML

In XHTML, the name attribute is deprecated. Use the global id attribute instead.

Attributes

= New in HTML5.
AttributeValueDescription
acceptfile_typeNot supported in HTML5.
Specifies a comma-separated list of file types  that the server accepts (that can be submitted through the file upload)
accept-charsetcharacter_setSpecifies the character encodings that are to be used for the form submission
actionURLSpecifies where to send the form-data when a form is submitted
autocompleteon
off
Specifies whether a form should have autocomplete on or off
enctypeapplication/x-www-form-urlencoded
multipart/form-data
text/plain
Specifies how the form-data should be encoded when submitting it to the server (only for method="post")
methodget
post
Specifies the HTTP method to use when sending form-data
nametextSpecifies the name of a form
novalidatenovalidateSpecifies that the form should not be validated when submitted
target_blank
_self
_parent
_top
Specifies where to display the response that is received after submitting the form

Global Attributes

The <form> tag also supports the Global Attributes in HTML.

Event Attributes

The <form> tag also supports the Event Attributes in HTML.

Try it Yourself - Examples

Form with checkboxes
A form with two checkboxes, and a submit button.
Form with radiobuttons
A form with two radio buttons, and a submit button.

Related Pages

HTML tutorial: HTML Forms and Input
HTML DOM reference: Form Object
CSS Tutorial: Styling Forms

Default CSS Settings

Most browsers will display the <form> element with the following default values:

Example

form {
  display: block;
  margin-top: 0em;
}
Try it Yourself »

No comments:

Post a Comment