Tag <form> HTML Reference

CSS Reference (New)


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  

Relative articles

Learning Foreign Words
Learning Foreign Words

Learning Foreign Words

Do you think that learning new foreign words is tedious? Each of us could face with learning of new languages. Sure, it can be tiresome especially if you try to remember a plenty of new words at once. But what if to memorize words sequentially, one by one? I believe that this is one of good solutions. I prepared a simple but at the same time efficient script that will help you in learning new words. This script takes a list of new words, and turns it into a slider where you have to guess if you know the word or not. If you are uncertain of the word – press the button ‘I know’, otherwise – just skip the word. We also can finish the test or do hint.
(more…)


Creating new HTML5/CSS3 single page layout – Art theme
Art HTML5&CSS3 single page layout

Creating new HTML5&CSS3 single page layout – Art theme

Today I will like to product new great masterpiece – new template with codename: ‘Art theme’. This will nice HTML5 template with nice gray colors. Hope that you will like new styles and you will learn some new coding lessons.

I going to start step-by-step tutorial for creating html5-css3 layout.

(more…)