Explain the form new input types in HTML5 ?
Last Updated :
30 Jul, 2024
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:
- color: This input type allows the user to select a color from a color picker.
- date: This input type allows the user to select a date from a drop-down calendar.
- time: This input type allows the user to enter a time.
- datetime: This input type allows the user to select date and time along with timezone.
- datetime-local: This input type allows the user to select both local date and time.
- week: This input type allows the user to select week and year from the drop-down calendar.
- email: This input type allows the user to enter an e-mail address.
- month: This input type allows the user to select a month and year from a drop-down calendar.
- number: This input type allows the user to enter a numerical value.
- range: This input type allows the user to enter a numerical value within a specified range.
- search: This input type allows the user to enter a search string within the input field.
- tel: This input type allows the user to enter a telephone number.
- 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:
Similar Reads
Non-linear Components
In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
JavaScript Tutorial
JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development
Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
Spring Boot Tutorial
Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML)
A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
HTML Tutorial
HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript
11 min read
React Interview Questions and Answers
React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
Steady State Response
In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We
9 min read
Backpropagation in Neural Network
Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
JavaScript Interview Questions and Answers
JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as
15+ min read