HTML Form Input Types

In HTML is an important element of HTML form. The "type" attribute of input element can be various types, which defines information field. Such as gives a text box.

Following is a list of all types of element of HTML.

type=" " Description
text Defines a one-line text input field
password Defines a one-line password input field
submit Defines a submit button to submit the form to server
reset Defines a reset button to reset all values in the form.
radio Defines a radio button which allows select one option.
checkbox Defines checkboxes which allow select multiple options form.
button Defines a simple push button, which can be programmed to perform a task on an event.
file Defines to select the file from device storage.
image Defines a graphical submit button.

HTML5 added new types on element. Following is the list of types of elements of HTML5

type=" " Description
color Defines an input field with a specific color.
date Defines an input field for selection of date.
datetime-local Defines an input field for entering a date without time zone.
email Defines an input field for entering an email address.
month Defines a control with month and year, without time zone.
number Defines an input field to enter a number.
url Defines a field for entering URL
week Defines a field to enter the date with week-year, without time zone.
search Defines a single line text field for entering a search string.
tel Defines an input field for entering the telephone number.

Following is the description about types of element with examples.

1. :

element of type "text" are used to define a single-line input text field.

Example:

Test it Now

Output:

Input "text" type:

The "text"field defines a sinlge line input text field.





Note:The default maximum cahracter lenght is 20.


2. :

The element of type "password" allow a user to enter the password securely in a webpage. The entered text in password filed converted into "*" or ".", so that it cannot be read by another user.

Example:

Test it Now

Output:

Input "password" type:

The "password"field defines a sinlge line input password field to enter the password securely.







3. :

The element of type "submit" defines a submit button to submit the form to the server when the "click" event occurs.

Example:

Test it Now

Output:

Input "submit" type:






After clicking on submit button, this will submit the form to server and will redirect the page to action value.We will learn about "action" attribute in later chapters


4. :

The type "reset" is also defined as a button but when the user performs a click event, it by default reset the all inputted values.

Example:

Test it Now

Output:

Input "reset" type:



Try to change the input values of user id and password, then when you click on reset, it will reset input fields with default values.


5. :

The type "radio" defines the radio buttons, which allow choosing an option between a set of related options. At a time only one radio button option can be selected at a time.

Example:

Test it Now

Output:

Input "radio" type

Kindly Select your favorite color

Red
blue
green
pink

6. :

The type "checkbox" are displayed as square boxes which can be checked or unchecked to select the choices from the given options.

Note: The "radio" buttons are similar to checkboxes, but there is an important difference between both types: radio buttons allow the user to select only one option at a time, whereas checkbox allows a user to select zero to multiple options at a time.

Example:

Test it Now

Output:

Input "checkbox" type


Registration Form

Kindly Select your favorite sports

Cricket
Tennis
Football
Baseball
Badminton


7. :

The type "button" defines a simple push button, which can be programmed to control a functionally on any event such as, click event.

Note: It mainly works with JavaScript.

Example:

Test it Now

Output:

Input "button" type.

Click the button to see the result:

Note: In the above example we have used the "alert" of JS, which you will learn in our JS tutorial. It is used to show a pop window.


8. :

The element with type "file" is used to select one or more files from user device storage. Once you select the file, and after submission, this file can be uploaded to the server with the help of JS code and file API.

Example:

Test it Now

Output:

Input "file" type.

We can choose any type of file until we do not specify it! The selected file will appear at next to "choose file" option


9. :

The type "image" is used to represent a submit button in the form of image.

Example:


HTML5 newly added types element

1. :

The type "color" is used to define an input field which contains a colour. It allows a user to specify the colour by the visual colour interface on a browser.

Note: The "color" type only supports color value in hexadecimal format, and the default value is #000000 (black).

Example:

Test it Now

Output:

Input "color" types:

Pick your Favorite color:

Up-click

Down-click

Note:The default value of "color" type is #000000 (black). It only supports color value in hexadecimal format.


2. :

The element of type "date" generates an input field, which allows a user to input the date in a given format. A user can enter the date by text field or by date picker interface.

Example:

Test it Now

Output:

Input "date" type

Select Start and End Date:

Start date:

End date:


3. :

The element of type "datetime-local" creates input filed which allow a user to select the date as well as local time in the hour and minute without time zone information.

Example:

Test it Now

Output:

Input "datetime-local" type


4. :

The type "email" creates an input filed which allow a user to enter the e-mail address with pattern validation. The multiple attributes allow a user to enter more than one email address.

Example:

Test it Now

Output:

Input "email" type

Note:User can also enter multiple email addresses separating by comma or whitespace as following:


5. :

The type "month" creates an input field which allows a user to easily enter month and year in the format of "MM, YYYY" where MM defines month value, and YYYY defines the year value. New

Example:

Test it Now

Output:

Input "month" type:


6. :

The element type number creates input filed which allows a user to enter the numeric value. You can also restrict to enter a minimum and maximum value using min and max attribute.

Example:

Test it Now

Output:

Input "number" type

Note:It will allow to enter number in range of 50-80. If you want to enter number other than range, it will show an error.


7. :

The element of type "url" creates an input filed which enables user to enter the URL.

Example:

Test it Now

Output:

Input "url" type



8. :

The type week creates an input field which allows a user to select a week and year form the drop-down calendar without time zone.

Example:

Test it Now

Output:

Input "week" type




9. :

The type "search" creates an input filed which allows a user to enter a search string. These are functionally symmetrical to the text input type, but may be styled differently.

Example:

Test it Now

Output:

Input "search" type


10. :

The element of type ?tel? creates an input filed to enter the telephone number. The "tel" type does not have default validation such as email, because telephone number pattern can vary worldwide.

Example:

Test it Now

Output:

Input "tel" type



Note: Here we are using two attributes that are "pattern" and"required" which will allow user to enter the number in given format and it is required to enter the number in input field.





Contact US

Email:[email protected]

HTML Form Input
10/30