Open In App

Explain the form new input types in HTML5 ?

Last Updated : 31 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss the functionality of the newer form input types provided by HTML5. Sometimes, while filling the registration form or any online form, it would require to follow the proper format to fill the particular data. Now it’s easy to use the webform to fill up the common data like date, email, url etc. There are almost 13 new input types introduced in HTML5 form. We will see all the input types & understand them one by one.

Input Type attributes:

  1. color: This input type allows the user to select a color from a color picker.
  2. date: This input type allows the user to select a date from a drop-down calendar.
  3. time: This input type allows the user to enter a time.
  4. datetime: This input type allows the user to select date and time along with timezone.
  5. datetime-local: This input type allows the user to select both local date and time.
  6. week: This input type allows the user to select week and year from the drop-down calendar.
  7. email: This input type allows the user to enter an e-mail address.
  8. month: This input type allows the user to select a month and year from a drop-down calendar.
  9. number: This input type allows the user to enter a numerical value.
  10. range: This input type allows the user to enter a numerical value within a specified range.
  11. search: This input type allows the user to enter a search string within the input field.
  12. tel: This input type allows the user to enter a telephone number.
  13. url: This input type allows the user to enter the URL.

We will use the above attributes & understand their usage through the example.

Example 1: In this example, you will get to know about color, date and time input type.

 

Date Syntax:

 <input type="date">

Time Syntax:

 <input type="time">

Color Syntax:

 <input type="color">

Note: date and time are not supported by the Internet Explorer and Safari browsers.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
            text-align: center;
        }
  
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>Welcome To GeeksforGeeks</h1>
  
    <form>
        <label for="color">Select Color : </label>
        <input type="color" />
    </form>
    <br />
  
    <form>
        <label for="date">Select Date : </label>
        <input type="date" />
    </form>
    <br />
  
    <form>
        <label for="time">Select Time :</label>
        <input type="time" />
    </form>
</body>
  
</html>


Output:

 

Example 2: In this example, you will get to know about datetime, datetime-local and week input type.

Datetime Syntax:

<input type=”datetime”>

Datetime-local Syntax:

 <input type="datetime-local">

Week Syntax:

 <input type="week">

Note: datetime-local and week are not supported by Firefox, Safari, and Internet Explorer browsers.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
            text-align: center;
        }
  
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>Welcome To GeeksforGeeks</h1>
  
    <form>
        <label for="date">Enter Date-Time : </label>
        <input type="datetime" />
    </form>
    <br />
  
    <form>
        <label for="date">Select Date-Time Local : </label>
        <input type="datetime-local" />
    </form>
    <br />
  
    <form>
        <label for="time">Select Week : </label>
        <input type="week" />
    </form>
</body>
  
</html>


Output:

Example 3: In this example, you will get to know about email, month, number and range input type.

Email Syntax:

<input type="email">

 

Month Syntax:

<input type="month">

Note: month is not supported by Firefox, Safari and Internet Explorer browsers. 

Number Syntax:

<input type="number">

Range Syntax:

<input type="range">

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
            text-align: center;
        }
  
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>Welcome To GeeksforGeeks</h1>
  
    <form>
        <label for="mail">Enter Email : </label>
        <input type="email" />
    </form>
    <br />
  
    <form>
        <label for="date">Select Month : </label>
        <input type="month" />
    </form>
    <br />
  
    <form>
        <label for="number">Select Number : </label>
        <input type="number" />
    </form>
    <br />
  
    <form>
        <label for="number">Select Number in Range : </label>
        <input type="range" min="1" max="10" step="1" />
    </form>
</body>
  
</html>


Output:

Example 4: In this example, you will get to know about search, tel and url input types.

Search Syntax:

<input type="search">

Tel Syntax:

<input type="tel">

Note:  Currently tel is not supported by any browser.

Url Syntax:

<input type="url">

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
            text-align: center;
        }
  
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>Welcome To GeeksforGeeks</h1>
  
    <form>
        <label for="search">Enter Search string : </label>
        <input type="search" placeholder="search ..." />
    </form>
    <br />
  
    <form>
        <label for="number">Enter Telephone No. : </label>
        <input type="tel" placeholder="xxx-xxx-xxxx" />
    </form>
    <br />
  
    <form>
        <label for="url">Enter Url : </label>
        <input type="url" placeholder="https://www..." />
    </form>
</body>
  
</html>


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads