In this article, I will demonstrate new input types in HTML 5. HTML 5 introduces several input types like Date, DateTime, DateTime-local, time, week, month, email, tel, URL, search, range, color, and number to improve the user experience and to make the forms more interactive. However, if a browser fails to recognize these new input types, it will treat them like a normal text box.
date |
It allows the user to select a date from a drop-down calendar. |
DateTime |
It allows the user to select a date and time along with time zone |
time |
It allows the user to enter time. |
DateTime-local |
It allows the user to select a local date and time |
week |
It allows the user to select a week and year from a drop-down calendar. |
month |
It allows the user to select a month and year from a drop-down calendar. |
email |
It allows the user to enter an e-mail address. |
tel |
It allows the user to enter the phone number with a specific pattern. |
URL |
It allows the user to enter a website URL |
search |
It's a text field for entering a search string |
range |
It allows the user to range the value with the slider. |
number |
It allows the user to enter a numeric value with the increase and decrease arrow. |
color |
It allows the user to select a color from the color picker |
Date input type
The date input type in HTML 5 allows the user to select a date from the datepicker calendar. It has got a next button and a pre-button with a closing round button in the center of next and pre. Below is the example of the date input type in HTML 5.
Example of date input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">date</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Date:</label>
- <input type="date" id="date" class="form-control col-md-3" />
- </div>
- </form>
- </div>
- </body>
- </html>
Datetime
Datetime input type allows the user to select date and time along with time zone but it does not support Internet Explorer, Firefox, Chrome or Opera browsers. It supports only Apple Safari. Below is an example of datetime input type in HTML 5.
Example of datetime input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">datetime</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Datetime:</label>
- <input type="datetime" id="datetime" class="form-control col-md-3" />
- </div>
- </form>
- </div>
- </body>
- </html>
Output
Datetime-local
Datetime-local input type in HTML 5 allows the user to select date and time. Similar to the datepicker, it has got a next and a pre-button with a closing round button in the center of next and pre, along with AM and PM options. Below is an example of datetime-local input type in HTML 5.
Example of datetime-local input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">datetime-local</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Datetime-local:</label>
- <input type="datetime-local" id="datetime" class="form-control col-md-3" />
- </div>
- </form>
- </div>
- </body>
- </html>
Output
Time
The time input type in HTML 5 allows the user to enter the time. Below is an example of a time input type.
Example of time input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">time</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Time:</label>
- <input type="time" id="time" class="form-control col-md-3" />
- </div>
- </form>
- </div>
- </body>
- </html>
Output
Week
Week input type in HTML 5 allows the user to select week and year from the datepicker drop-down. Below is an example of a week's input type.
Example of week input type/span>
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">week</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Week:</label>
- <input type="week" id="week" class="form-control col-md-3" />
- </div>
- </form>
- </div>
- </body>
- </html>
Output
Month
Month input type in HTML 5 allows the user to select month and year from the datepicker drop-down. Below is an example of the month input type.
Example of month input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">month</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Month:</label>
- <input type="month" id="month" class="form-control col-md-3" />
- </div>
- </form>
- </div>
- </body>
- </html>
Output
Email
The email input type in HTML 5 allows the user to enter the email address. It behaves like a textbox if required and pattern attribute is not used along with it. Below is an example of the email input type.
Example of email input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">email</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Email:</label>
- <input type="email" id="email" placeholder="email address" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" class="form-control col-md-3" required/>
- </div>
- <button class="btn-primary rounded-0">Submitt</button>
- </form>
- </div>
- </body>
- </html>
Output
Tel
Tel input type in HTML 5 allows the user to enter a phone number. It behaves like a textbox if required and the pattern attribute does not get used along with it. Below is an example of a tel input type.
Example of tel input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">tel</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Phone Number:</label>
- <input type="tel" id="phone" placeholder="Phone Number" pattern="\d{10}$" class="form-control col-md-3" required/>
- </div>
- <button class="btn-primary rounded-0">Submitt</button>
- </form>
- </div>
- </body>
- </html>
Output
Number
The number input type in HTML 5 allows the user to enter an only numeric value. It has increment and decrement arrows to increase and decrease number values. Below is an example of the number input type.
Example of number input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">number</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Number:</label>
- <input type="number" id="number" class="form-control col-md-3"/>
- </div>
- </form>
- </div>
- </body>
- </html>
Output
URL
URL input type in HTML 5 is used to enter a valid website address or URL. It has an attribute pattern to specify the URL. It has multiple attributes that allow the user to enter multiple URLs. Below is an example of a URL input type.
Example of url input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">url</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>URL:</label>
- <input type="url" id="url" pattern="https?://.+" class="form-control col-md-3" required/>
- </div>
- <button class="btn-primary rounded-0">Submitt</button>
- </form>
- </div>
- </body>
- </html>
Output
Search
The search input type can be used for creating search fields. A search field behaves like a regular textbox, but in some browsers, like Google Chrome and Apple Safari, as soon as you start typing in a search box a small cross appears on the right side of the text box that lets you quickly clear the search textbox.
Example search input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">search</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Search:</label>
- <input type="search" id="search" class="form-control col-md-3" />
- </div>
- </form>
- </div>
- </body>
- </html>
Output
Range
The range input type can be used for entering a numerical value within a specified range. It is similar to the number input, but it offers a simpler control for entering a number. It has got a slider to increase and decrease the range value.
Example of range input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">range</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Range:</label>
- <input type="range" id="range" class="custom-range"/>
- </div>
- </form>
- </div>
- </body>
- </html>
Output
Color
The color input type allows the user to select a color from a color picker and returns the hex value for that color.
Example of color input type
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container py-5">
- <h4><span class="text-danger">color</span> input type in html 5</h4>
- <form>
- <div class="form-group">
- <label>Color:</label>
- <input type="color" id="color"/>
- </div>
- </form>
- </div>
- </body>
- </html>
Output
In this article, we studied List Of New Input Types In HTML 5.