Forms
An HTML form is used to collect user input. The user input is most often sent to a server for processing. An HTML form contains different kind of information such as username, password, contact number, email id etc.
There are various form elements available like text fields, text-area fields, radio buttons, submit buttons, check-boxes etc. Using these elements the information of a user is submitted on a web server.
The <form>tag is used to create an HTML form and it has following syntax −
The <input> Element
Input Elements are the most common elements which are used in HTML Forms.
An <input> element can be displayed in many ways, depending on the type attribute.
Few examples are as follows:
- <input type="text">
- <input type="number">
- <input type="button">
- <input type="checkbox">
- <input type="email">
- <input type="password">
- <input type="radio">
- <input type="submit">
- <input type="image">
- <input type="date">
- <input type="month">
- <input type="range">
- <input type="reset">
- <input type="search">
- <input type="time">
- <input type="color">
- <input type="url">
The <input> tag has following syntax −
The <label> Element
The <label> tag defines a label for many form elements.
The <label> tag in HTML is used to provide a usability improvement for mouse users i.e, if a users clicks on the text within the<label> element, it toggles the control.
To associate the <label> with an <input> element, you need to give the <input> an id attribute. The <label> then needs a for attribute whose value is same as input’s id.
The <label> tag has following syntax −
Example :
This will produce the following result −
Radio Buttons in HTML Form :
Radio Buttons are used to let the user select exactly one option from a list of predefined options.
Example :
This will produce the following result −
Checkboxes in HTML Form :
Checkboxes are used to let the user select one or more options from a pre-defined set of options.
Example :
This will produce the following result −
Select Boxes in HTML Forms :
Select boxes are used to allow users to select option from a pull-down list of options.
Select boxes are created using two elements which are <select>and <option>. List items are defined within the select element.
Example :
This will produce the following result −