HTML Input Types
Here are the different input types you can use in HTML:
<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">
<input type="week">
<input type="text"> defines a single-line text input field:
type="text", type="password", type="submit", and type="reset".<!DOCTYPE html> <html> <head> <title>Login Form Example</title> </head> <body> <h2>User Authentication</h2> <form action="/action_page.php"> <label for="username">Username:</label><br> <input type="text" id="username" name="username" value="JohnDoe"><br><br> <label for="pwd">Password:</label><br> <input type="password" id="pwd" name="pwd"><br><br> <input type="submit" value="Login"> <input type="reset" value="Reset"> </form> </body> </html>
type="text" creates a standard single-line input field, type="password" masks characters with bullets or asterisks, type="submit" sends the data, and type="reset" clears the form back to initial values.
type="radio" with matching name attributes for single selection, and type="checkbox" for multi-selection.<!DOCTYPE html> <html> <head> <title>Radio and Checkbox Example</title> </head> <body> <h2>User Preferences</h2> <form action="/action_page.php"> <p>Select Gender (Choose one):</p> <input type="radio" id="male" name="gender" value="male"> <label for="male">Male</label><br> <input type="radio" id="female" name="gender" value="female"> <label for="female">Female</label><br><br> <p>Select Hobbies (Choose many):</p> <input type="checkbox" id="coding" name="hobby1" value="coding"> <label for="coding">Coding</label><br> <input type="checkbox" id="music" name="hobby2" value="music"> <label for="music">Music</label><br><br> <input type="submit" value="Submit"> </form> </body> </html>
Select Gender (Choose one):
Select Hobbies (Choose many):
name attribute ensures only one item can be selected at a time. Checkboxes allow choosing zero, one, or several options independently.
type="date" for calendar selection and type="color" for the color picker.<!DOCTYPE html> <html> <head> <title>Date and Color Picker Example</title> </head> <body> <h2>Event Customization</h2> <form action="/action_page.php"> <label for="eventdate">Event Date:</label><br> <input type="date" id="eventdate" name="eventdate"><br><br> <label for="themecolor">Theme Color:</label><br> <input type="color" id="themecolor" name="themecolor" value="#ff0000"><br><br> <input type="submit" value="Save Settings"> </form> </body> </html>
type="date" provides a native date picker dropdown, while type="color" triggers a color picker palette interface.
type="button" together with the onclick event attribute.<!DOCTYPE html> <html> <head> <title>Input Button Example</title> </head> <body> <h2>Interactive Input Button</h2> <p>Click the button below to trigger JavaScript action:</p> <input type="button" onclick="alert('Welcome to HTML Input Types!')" value="Click Me!"> </body> </html>
Click the button below to trigger JavaScript action:
type="button" defines a standard push button that has no submit action by default, making it ideal for client-side JavaScript interactions via attributes like onclick.