Input Type Elements in HTML5 with New Types Examples

In this tutorial, learn all input type elements in HTML including the new elements introduced in HTML5. The elements are useful to create a meaningful form to get important data from users online.

Let’s find out these input type elements in detail given here below.

List of Form Input Type Elements in HTML with New Introduced in HTML5

The different types of input type elements in HTML and newly introduced elements from HTML5 are given below:

<input> elements in HTML

Input Type Elements Description New in HTML5
<input type="button"> It defines a simple button element. No
<input type="checkbox"> It defines a checkbox to select multiple options. No
<input type="color"> It defines an input field to select a specific color. Yes
<input type="date"> It defines an input field to select a date. Yes
<input type="datetime-local"> It defines an input field to enter a date without a time zone. Yes
<input type="email"> It defines an input field to enter email addresses. No
<input type="file"> It defines an input field to select a file from the storage device. No
<input type="hidden"> It defines a hidden input field that is invisible to users. No
<input type="image"> It defines a graphical submit button in a form. No
<input type="month"> It defines an input box to select a month and a year. Yes
<input type="number"> It defines an input field to enter a number. No
<input type="password"> It defines an input box to enter a password. No
<input type="radio"> It defines a radio button that allows selecting a single option. No
<input type="range"> It defines a control to select a number. Yes
<input type="reset"> It defines a button to reset form values. No
<input type="search"> It defines an input field to enter a search string. Yes
<input type="submit"> It defines a submit button to submit the form. No
<input type="tel"> It defines an input field to enter a number. Yes
<input type="text"> It defines an input box to enter text content. No
<input type="time"> It allows users to select a time. Yes
<input type="url"> It defines a field to enter a URL. Yes
<input type="week"> It defines a field to select a week and year. Yes

Let’s learn these elements in detail with useful examples.

HTML Input Type Elements with Examples

Input Type Text

The <input type="text"> element is a single-line input text box to enter text content. It is useful to get user’s input like first name, last name, full name, address, and many more.

Test it Live

Output

HTML input type text element

The above example contains the two input text boxes. The first box is for the first name and the second input box is for the last name.

Input Type Email

<input type="email"> is single-line input box to get email addresses from users. The users need to enter the text in the form of an email address to allow submit the form. If the users do not enter an email address, it will not allow them to submit the form.

Test it Live

Output

HTML input type email elements

The above example contains the single input box that takes the email id as an input.

Input Type Password

<input type="password"> creates a single-line textbox to enter passwords. It is useful to create a login form online for users with a password field. It shows hidden content or dot(.) to users when they enter some value on it. The entered content is not visible to users.

Test it Live

Output

HTML input type password elements

You can enter your content on the above input box to get the result in the password text box.

Input Type Submit

<input type="submit"> create a button that is useful to submit a form. It appears like a button with some text visible inside it. When the users click the submit button, it performs some action given in the action attribute of <form> element. The text contained in the button is the text you specify in the value attribute.

Test it Live

Output

HTML input type submit element

The above example shows the button created using these input type elements. When the users submit the form, it performs some action and gives results according to the script in a file.

Input Type Reset

<input type="reset"> creates a button that reset the form to its initial condition on click. It is useful in a form to allow users to easily get the initial condition of the form. You don’t need to give it a text as ‘reset’ is the default text for this. However, you can change the text content using value attribute.

Test it Live

Output

HTML input type reset element

You can fill the above form and click the reset button to change it to its initial condition.

Input Type Radio Elements

<input type="radio"> is used in radio groups that is a collection of the radio buttons to display options. It is useful when you want to give choices to your users to select one. You will be able to select a single option from the radio button choices.

Test it Live

Output

HTML input type radio elements

The above example contains two radio buttons to select gender. You can click on your choice to select a single option.

Input Type Checkbox

<input type="checkbox"> create a group of square-shaped boxes to give options to users. You can allow users to select single or multiple options together. To activate the option, you have to click on it to make the checkbox checked. When you click on the checkbox, it adds a tick () mark that indicates the checkbox option is selected or activated.

Test it Live

Output

HTML input type checkbox element

You can select a single option or multiple options from the choices given above. Checkboxes give more flexibility to users to select choices according to their requirements.

Input Type Button

<input type="button"> creates a button element that can be useful to execute a script on click. You can add your script or function inside the onclick attribute of this input type element. It contains a text that you can change or modify using the value attribute on it.

Test it Live

Output

HTML input type button element

The above example shows a button that displays an alert box on click. Similarly, you can add any other scripts or function that contains script somewhere else in the content.

Input Type Color Elements

<input type="color"> creates an input field that looks like a color picker where users can select a color. It allows users to easily specify a color with visualize interface.

Test it Live

Output

HTML input type color Input Type Elements in HTML with New Types in HTML5

You can click the above color picker to select a color of your choice. It makes it easier for users to specify a color without entering the color codes.

Input Type Date

<input type="date"> is input type elements in HTML5 that allow users to enter a date. It contains a calendar icon that you click to get a date picker and select a date of your choice. You can add this field to make it easier enter a date in the input field using the date picker.

Test it Live

Output

HTML input type date element

The above example contains the date format and a calendar icon. When you click the calendar icon, it displays a calendar to select and enter any date.

Input Type Datetime-local Elements

<input type="datetime-local"> are input type elements in HTML5 that allow users to select dates and times with no time zone. It contains a date format and a calendar icon that you click to get a DateTime picker. The field makes it easier to enter a date and time with no time zone using the date-time picker.

Test it Live

Output

HTML input type datetime local Input Type Elements in HTML with New Types in HTML5

The above example contains the date format and time fill in the blanks with a calendar icon. When you click the calendar icon, it displays a calendar to select any date and time of your choice.

Input Type File

<input type="file"> creates a browse button that contains the text ‘Choose File’ inside it and ‘No file chosen’ outside it. When you click on the button, it browses the storage directory files to select one for file upload. It is useful to get files as input from users in a form.

Test it Live

Output

HTML input type file element

You can click the above browse button that browses the storage directory file to select for uploading.

Input Type Hidden Elements

<input type="hidden"> is an input field that is hidden and not visible to users in a form. It is useful to add a hidden value or data in a form to get on form submission. The users are not able to see the hidden data or modify it.

Test it Live

Output

Hidden element

The above example contains a hidden input field in a form with a customer id stored in it. However, users are not able to see the hidden data that is tracked and updated in a database.

Input Type Image

<input type="image"> is the submit button that appears as an image. You can add an image in place of a submit button in a form. When the users click on the image, the form gets submitted. It requires to specify the path of the image to display as given below:

Test it Live

Output

Image elements

The above example shows an image in place of submit button in a form. You can click on the image to submit the above form.

Input Type Month

<input type="month"> are input type elements in HTML5 that allow users to select month and year. It contains a fill in the blank and a calendar icon to fill that with the month and year picker. The field makes it easier to enter a month and year without the need for manual entry.

Test it Live

Output

Month Element

You can click the above calendar icon to select the month and year of your choice.

Input Type Number

<input type="number"> is single-line input field that takes input as a numeric value. You can specify the minimum and maximum numbers allow in the input box using the min and max attributes.

Test it Live

Output

number element

The above example contains an input box where users are allowed to enter numbers between 1 to 10.

Input Type Range Elements

<input type="range"> creates a control to enter a number using the number slider. The default range is from 0 to 100 and you can change the minimum and maximum value using min and max attributes. However, the exact value is not important in this number slider. Users can use this input field only when they know that the exact value is not important.

Test it Live

Output

range element

The above example contains the range slider to select a number between ranges 1 to 20.

Input Type Search

<input type="search"> is single-line input box where users have to enter a search queries. It can be useful for site search in a website. You can use it on your website to allow users to enter a search term. It performs a search on the site for search engines (like Google search and others).

Test it Live

Output

Search element

You can enter a search term on the above text box to check the input field.

Input Type Tel Elements

<input type="tel"> are input type elements in HTML5 that take mobile phone numbers as input. You can add a placeholder attribute to guide users to enter the correct format of mobile numbers.

Test it Live

Output

Tel element

The above example shows an input box that shows the format of the mobile number to enter in the input box. You can change the format and specify your required format in the placeholder attribute.

Input Type Time

<input type="time"> creates input type elements in HTML5 where users can specify time using a time calendar. The input box contains fill in blanks and a calendar icon to get a time calendar. You can click the time calendar icon and select your time you want to enter in the input box.

Test it Live

Output

Time element

When you click the calendar icon, it displays time in an hour and minutes and PM or AM.

Input Type URL Elements

<input type="url"> is a single-line input field to enter the URL of a website. When you make this input field required, it will not allow users to submit the form until they fill the URL format on it.

Test it Live

Output

URL element

You can make the above field required and enter the content to check the working of the input field.

Input Type Week

<input type="week"> creates input type elements in HTML5 to select week and year. It contains a fill in the blank and a calendar icon to get a week calendar. You have to click the calendar icon to fill the week and the year in the input box.

Test it Live

Output

week

You can click the above calendar icon to fill the week and year in the input box.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.