Tag <form> HTML Reference

Example

An HTML form with two input fields and one submit button:

<form action="form_action.php" method="get">
  First name: <input type="text" name="firstname" /><br />
  Last name: <input type="text" name="lastname" /><br />
  <input type="submit" value="Submit" />
</form>

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

1. 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:

An HTML form is used to pass data to a server.

Tip: The <form> element is a block-level element, and browsers create a line break before and after a form.


2. Differences Between HTML and XHTML

In XHTML, the name attribute of the <form> tag is deprecated, and will be removed. Use the id attribute instead.


3. Required Attributes

DTD indicates in which HTML 4.01/XHTML 1.0 DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.

Attribute Value Description DTD
action URL Specifies where to send the form-data when a form is submitted STF

4. Optional Attributes

Attribute Value Description DTD
accept MIME_type Specifies the types of files that the server accepts (that can be submitted through a file upload) STF
accept-charset character_set Specifies a list of character encodings that the server accepts STF
enctype application/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") STF
method get
post
Specifies the HTTP method to use when sending form-data STF
name name Specifies the name of a form TF
target _blank
_self
_parent
_top
framename
Deprecated. Specifies where to display the response that is received after submitting the form TF

5. Standard Attributes

The <form> tag supports the following standard attributes:

Attribute Value Description DTD
class classname Specifies a classname for an element STF
dir rtl
ltr
Specifies the text direction for the content in an element STF
id id Specifies a unique id for an element STF
lang language_code Specifies a language code for the content in an element STF
style style_definition Specifies an inline style for an element STF
title text Specifies extra information about an element STF
xml:lang language_code Specifies a language code for the content in an element, in XHTML documents STF

6. Event Attributes

The <form> tag supports the following event attributes:

Attribute Value Description DTD
onclick script Script to be run on a mouse click STF
ondblclick script Script to be run on a mouse double-click STF
onmousedown script Script to be run when mouse button is pressed STF
onmousemove script Script to be run when mouse pointer moves STF
onmouseout script Script to be run when mouse pointer moves out of an element STF
onmouseover script Script to be run when mouse pointer moves over an element STF
onmouseup script Script to be run when mouse button is released STF
onkeydown script Script to be run when a key is pressed STF
onkeypress script Script to be run when a key is pressed and released STF
onkeyup script Script to be run when a key is released STF
onreset script Script to be run when a form is reset  
onsubmit script Script to be run when a form is submitted  

Other HTML/XHTML tags:


Relative articles

Creating Ajaxy Photo Gallery (jQuery) with Custom Images Sets
ajaxy photo gallery (jQuery) with custom images sets

Creating ajaxy photo gallery (jQuery) with custom images sets

Today we will make simple and nice jQuery gallery which will load images ‘ajaxy’. Also our gallery will support working with predefined custom sets of images. I hope that our result will interesting for you.

(more…)


CSS3 Animated Photo Slider
CSS3 Animated Photo Slider

CSS3 Animated Photo Slider

Today I have prepared new great CSS3 demonstration. This is 3D slideshow where I have used WebKit CSS 3D transforms. On the demo you will see a free-floating 3D object with photos. Hint – you have to use Chrome or Safari browser to see all these delights.
(more…)