HTML Input Types
HTML Input Types
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
This chapter describes the different types for the HTML <input> element.
• <input type="button">
• <input type="checkbox">
• <input type="color">
• <input type="date">
• <input type="datetime-local">
• <input type="email">
• <input type="file">
• <input type="hidden">
• <input type="image">
• <input type="month">
• <input type="number">
• <input type="password">
• <input type="radio">
• <input type="range">
• <input type="reset">
• <input type="search">
• <input type="submit">
• <input type="tel">
• <input type="text">
• <input type="time">
• <input type="url">
Tutorials
• <input Exercises
type="week"> Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
Example
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
Try it Yourself »
First name:
Last name:
Example
<form>
Tutorials Exercises Services
<label for="username">Username:</label><br>
Sign Up Log in
Try it Yourself »
Username:
Password:
The form-handler is typically a server page with a script for processing input data.
Example
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
Tutorials Exercises Services Sign Up Log in
Try itCSS
HTML YourselfJAVASCRIPT
» SQL PYTHON JAVA PHP HOW TO W3.CSS
First name:
John
Last name:
Doe
Submit
If you omit the submit button's value attribute, the button will get a default text:
Example
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit">
</form>
Try it Yourself »
Example
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
Tutorials
<label Exercises name:</label><br>
for="lname">Last Services Sign Up Log in
<input type="text" id="lname" name="lname" value="Doe"><br><br>
HTML
CSS type="submit"
<input JAVASCRIPT value="Submit">
SQL PYTHON JAVA PHP HOW TO W3.CSS
<input type="reset" value="Reset">
</form>
Try it Yourself »
First name:
John
Last name:
Doe
Submit Reset
If you change the input values and then click the "Reset" button, the form-data will
be reset to the default values.
Radio buttons let a user select ONLY ONE of a limited number of choices:
Example
<form>
<input type="radio" id="html" name="fav_language" value="HTML">
<label for="html">HTML</label><br>
<input type="radio" id="css" name="fav_language" value="CSS">
<label for="css">CSS</label><br>
<input type="radio" id="javascript" name="fav_language"
value="JavaScript">
Tutorials
<label Exercises Services
for="javascript">JavaScript</label> Sign Up Log in
</form>
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
Try it Yourself »
HTML
CSS
JavaScript
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
Example
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>
Try it Yourself »
I have a bike
I have a car
I have a boat
InputTutorials
Type
Button
Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
<input type="button"> defines a button:
Example
Try it Yourself »
Click Me!
Depending on browser support, a color picker can show up in the input field.
Example
<form>
<label for="favcolor">Select your favorite color:</label>
<input type="color" id="favcolor" name="favcolor">
</form>
Try it Yourself »
Depending on browser support, a date picker can show up in the input field.
Tutorials Exercises Services Sign Up Log in
Example
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
<form>
<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday">
</form>
Try it Yourself »
You can also use the min and max attributes to add restrictions to dates:
Example
<form>
<label for="datemax">Enter a date before 1980-01-01:</label>
<input type="date" id="datemax" name="datemax" max="1979-12-31">
<br><br>
<label for="datemin">Enter a date after 2000-01-01:</label>
<input type="date" id="datemin" name="datemin" min="2000-01-02">
</form>
Try it Yourself »
Depending on browser support, a date picker can show up in the input field.
Example
<form>
<label for="birthdaytime">Birthday (date and time):</label>
<input type="datetime-local" id="birthdaytime" name="birthdaytime">
Tutorials
</form> Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
Try it Yourself »
Some smartphones recognize the email type, and add ".com" to the keyboard to
match email input.
Example
<form>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email">
</form>
Try it Yourself »
Example
<form>
<input type="image" src="img_submit.gif" alt="Submit" width="48"
height="48">
Tutorials
</form> Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
Try it Yourself »
Example
<form>
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">
</form>
Try it Yourself »
A hidden field lets web developers include data that cannot be seen or modified by
users when a form is submitted.
A hidden field often stores what database record that needs to be updated when
the form is submitted.
Note: While the value is not displayed to the user in the page's content, it is visible
(and can be edited) using any browser's developer tools or "View Source"
functionality. Do not use hidden inputs as a form of security!
Example
<form>
Tutorials Exercises Services
<label for="fname">First name:</label>
Sign Up Log in
Try it Yourself »
Depending on browser support, a date picker can show up in the input field.
Example
<form>
<label for="bdaymonth">Birthday (month and year):</label>
<input type="month" id="bdaymonth" name="bdaymonth">
</form>
Try it Yourself »
The following example displays a numeric input field, where you can enter a value
from 1 to 5:
Example
<form>
Tutorials Exercises Services
<label for="quantity">Quantity (between 1 and 5):</label>
Sign Up Log in
Try it Yourself »
Input Restrictions
Here is a list of some common input restrictions:
Attribute Description
You will learn more about input restrictions in the next chapter.
The following example displays a numeric input field, where you can enter a value
from 0 to 100, in steps of 10. The default value is 30:
Example
<form>
Tutorials Exercises Services
<label for="quantity">Quantity:</label>
Sign Up Log in
Try it Yourself »
Example
<form>
<label for="vol">Volume (between 0 and 50):</label>
<input type="range" id="vol" name="vol" min="0" max="50">
</form>
Try it Yourself »
Example
<form>
<label for="gsearch">Search Google:</label>
<input type="search" id="gsearch" name="gsearch">
</form>
Tutorials Exercises Services Sign Up Log in
Try itCSS
HTML YourselfJAVASCRIPT
» SQL PYTHON JAVA PHP HOW TO W3.CSS
Example
<form>
<label for="phone">Enter your phone number:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-
[0-9]{3}">
</form>
Try it Yourself »
Depending on browser support, a time picker can show up in the input field.
Example
<form>
<label for="appt">Select a time:</label>
<input type="time" id="appt" name="appt">
</form>
Try it Yourself »
Tutorials Exercises Services Sign Up Log in
Input
HTMLCSS Type Url
JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
The <input type="url"> is used for input fields that should contain a URL
address.
Depending on browser support, the url field can be automatically validated when
submitted.
Some smartphones recognize the url type, and adds ".com" to the keyboard to
match url input.
Example
<form>
<label for="homepage">Add your homepage:</label>
<input type="url" id="homepage" name="homepage">
</form>
Try it Yourself »
Depending on browser support, a date picker can show up in the input field.
Example
<form>
<label for="week">Select a week:</label>
<input type="week" id="week" name="week">
</form>
Try it Yourself »
Tutorials Exercises Services Sign Up Log in
HTML
HTMLCSS Exercises
JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
Exercise:
In the form below, add an input field for text, with the name "username" .
<form action="/action_page.php">
< >
</form>
Submit Answer »
❮ Previous Next ❯
W3schools Pathfinder
Track your progress - it's free! Sign Up Log in
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
COLOR PICKER
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
Tutorials
How To Tutorial
NEWSLETTER
Exercises Services
GET CERTIFIED
CONTACT US
Sign Up Log in
SQL Tutorial
HTML
CSS Python Tutorial
JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
FORUM
Java Tutorial ABOUT CLASSROOM
C++ Tutorial
W3Schools is optimized for learning and training. Examples might be simplified to
jQuery Tutorial
improve reading and learning.
Top References
Tutorials, references, and examples are constantly reviewed to avoid errors, but
we cannot warrant full correctness
of all Reference
HTML content. While using W3Schools, you agree to have read and accepted our
terms of use, cookie and privacy policy.
CSS Reference
JavaScript Reference
Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is
SQL Reference
Powered by W3.CSS.
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference