HTML Forms PDF
HTML Forms PDF
HTML Forms PDF
w3schools.com
HTML Forms
❮ Previous Next ❯
Submit
Try it Yourself »
<form>
.
form elements
.
</form>
Form elements are different types of input elements, like: text fields, checkboxes, radio
buttons, submit buttons, and more.
The <input> element is displayed in several ways, depending on the type attribute.
Type Description
<input type="radio"> Defines a radio button (for selecting one of many choices)
You will learn a lot more about input types later in this tutorial.
Text Fields
<input type="text"> defines a single-line input field for text input.
Example
A form with two text input fields:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
Try it Yourself »
First name:
Last name:
Note: The form itself is not visible. Also note that the default width of an input field is
20 characters.
The <label> element is useful for screen-reader users, because the screen-reader will
read out load the label when the user is focused on the input element.
The <label> element also help users who have difficulty clicking on very small regions
(such as radio buttons or checkboxes) - because when the user clicks the text within
the <label> element, it toggles the radio button/checkbox.
The for attribute of the <label> tag should be equal to the id attribute of the
<input> element to bind them together.
Radio Buttons
<input type="radio"> defines a radio button.
Example
A form with radio buttons:
<form>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="other">
<label for="other">Other</label>
</form>
Try it Yourself »
Male
Female
Other
The form-handler is typically a page on the server with a script for processing input
data.
Example
A form with a submit button:
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
Try it Yourself »
First name:
John
Last name:
Doe
Submit
Usually, the form data is sent to a page on the server when the user clicks on the
submit button.
In the example above, the form data is sent to a page on the server called
"/action_page.php". This page contains a server-side script that handles the form data:
<form action="/action_page.php">
If the action attribute is omitted, the action is set to the current page.
The default value is " _self " which means the form will be submitted in the current
window.
To make the form result open in a new browser tab, use the value " _blank ".
Example
Here, the submitted result will open in a new browser tab:
Try it Yourself »
Other legal values are " _parent ", " _top ", or a name representing the name of an
iframe.
Example
Use the GET method when submitting the form:
Try it Yourself »
or:
Example
Use the POST method when submitting the form:
Try it Yourself »
However, when GET is used, the form data will be visible in the page's address
field:
/action_page.php?firstname=John&lastname=Doe
Notes on GET:
Notes on POST:
POST has no size limitations, and can be used to send large amounts of data.
Form submissions with POST cannot be bookmarked
If the name attribute is omitted, the data of that input field will not be sent at all.
Example
This example will not submit the value of the "First name" input field:
<form action="/action_page.php">
<label for="fname">First name:</label><br>
file:///C:/Users/Peregrin0/Documents/cursos programacion/www.w3schools.com/html/html_forms.html 7/12
21/4/2020 HTML Forms
Try it Yourself »
HTML Exercises
Exercise:
In the form below, add an input field with the type "button" and the value "OK".
<form>
< >
</form>
Submit Answer »
Attribute Description
accept- Specifies the charset used in the submitted form (default: the page
charset charset).
action Specifies an address (url) where to submit the form (default: the
submitting page).
method Specifies the HTTP method used when submitting the form (default:
GET).
name Specifies a name used to identify the form (for DOM usage:
document.forms.name).
novalidate Specifies that the browser should not validate the form.
target Specifies the target of the address in the action attribute (default:
_self).
You will learn more about the form attributes in the next chapters.
❮ Previous Next ❯
COLOR PICKER
HOW TO
Tabs
Dropdowns
Accordions
Side Navigation
Top Navigation
Modal Boxes
Progress Bars
Parallax
Login Form
HTML Includes
Google Maps
Range Sliders
Tooltips
Slideshow
Filter List
Sort List
SHARE
CERTIFICATES
HTML
CSS
JavaScript
SQL
Python
PHP
jQuery
Bootstrap
XML
Read More »
REPORT ERROR
PRINT PAGE
FORUM
ABOUT
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
jQuery Tutorial
Java Tutorial
C++ Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
jQuery Reference
Java Reference
Angular Reference
Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
jQuery Examples
Java Examples
XML Examples
Web Certificates
HTML Certificate
CSS Certificate
JavaScript Certificate
SQL Certificate
Python Certificate
jQuery Certificate
PHP Certificate
Bootstrap Certificate
XML Certificate
Get Certified »
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve
reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid
errors, but we cannot warrant full correctness of all content. While using this site, you agree to have
read and accepted our terms of use, cookie and privacy policy. Copyright 1999-2020 by Refsnes Data.
All Rights Reserved.
Powered by W3.CSS.