Copyright ©

HTML <form> tag



The HTML <form> tag is used for creating a form for user input. A form can contain textfields, checkboxes, radio-buttons and more. Forms are used to pass user-data to a specified URL.

Difference between HTML and XHTML:



<form action="/cgi-bin/hello_get.cgi" method="get">
First name: 
<input type="text" name="first_name" value="" maxlength="100" />
<br />
Last name: 
<input type="text" name="last_name" value="" maxlength="100" />
<input type="submit" value="Submit" />

This will produce following result:

First name:
Last name:

Online Practice:

To Become more comfortable - Do Online Practice


actionURLSpecifies a URI/URL of the back-end script that will process the form.
acceptcontent typesSpecifies a comma-separated list of content types that the server accepts.
accept-charsetcharset listSpecifies a list of character encodings that the server accepts. The default value is "unknown".
enctypemimetypesThe mime type used to encode the content of the form.
Specifies the HTTP method to use when the form is submitted. Possible values:
  • get (the form data is appended to the URL when submitted)
  • post (the form data is not appended to the URL)
namefrom nameDefines a unique name for the form

Target to open the given URL.

  • _blank - the target URL will open in a new window
  • _self - the target URL will open in the same frame as it was clicked
  • _parent - the target URL will open in the parent frameset
  • _top - the target URL will open in the full body of the window

Standard Attributes:

classDocument wide identifier
dirSpecifies the direction of the text
idDocument wide identifier
titleSpecifies a title to associate with the element.
styleHelps to include inline casecadubf style sheet.
langSets the language code.

Event Attributes:

onclickScript runs when a mouse click
ondblclickScript runs when a mouse double-click
onmousedownScript runs when mouse button is pressed
onmouseupScript runs when mouse button is released
onmouseoverScript runs when mouse pointer moves over an element
onmousemoveScript runs when mouse pointer moves
onmouseoutScript runs when mouse pointer moves out of an element
onkeypressScript runs when key is pressed and released
onkeydownScript runs when key is pressed
onkeyupScript runs when key is released
onsubmitScript runs when from is submitted
onresetScript runs when from is reset

Copyright ©