HTML Input Types: Complete Guide with Examples
HTML input types are an essential part of web development because they allow users to enter different kinds of information into forms. Whether you are creating a login page, registration form, contact form, search box, booking system, or online application, HTML input elements help collect data from website visitors in a structured and user-friendly way.
HTML provides multiple input types, including text fields, passwords, email addresses, numbers, dates, checkboxes, radio buttons, file uploads, and more. Each input type is designed for a particular purpose and provides different features to improve the user experience.
Understanding HTML input types is important for beginners and experienced developers because selecting the correct input type makes forms easier to use, improves data entry, and enables built-in browser validation.
In this detailed guide, you will learn about all commonly used HTML input types, their syntax, practical examples, attributes, and best practices.
What Are HTML Input Types?
HTML input types define the kind of data a user can enter or select in an HTML form. They are specified using the type attribute of the <input> element.
The <input> element is one of the most frequently used HTML form elements. It allows users to provide information through different types of controls.
Basic syntax:
<input type="text" name="username">In this example:
<input>creates an input field.type="text"specifies that the user can enter plain text.name="username"identifies the input when form data is submitted.
The appearance and functionality of an input field depend on its specified type. For example, a password input hides entered characters, while an email input provides browser-based email validation.
List of HTML Input Types
HTML supports several input types that serve different purposes.
The following table provides an overview of commonly used HTML input types.
| Input Type | Description |
|---|---|
text | Accepts a single line of text. |
password | Accepts hidden password characters. |
email | Accepts an email address. |
number | Accepts numerical values. |
tel | Accepts telephone numbers. |
url | Accepts website URLs. |
search | Creates a search input field. |
date | Allows users to select a date. |
time | Allows users to select a time. |
datetime-local | Selects a date and local time. |
month | Selects a month and year. |
week | Selects a week and year. |
checkbox | Allows multiple selections. |
radio | Allows one selection from a group. |
file | Allows users to upload files. |
color | Opens a color picker. |
range | Creates a slider control. |
hidden | Stores data that is not displayed. |
submit | Submits a form. |
reset | Resets form controls. |
button | Creates a clickable button. |
image | Creates an image-based submit button. |
Let’s understand each HTML input type with its syntax and examples.
1. HTML Text Input Type
The text input type creates a single-line text field. It is commonly used to collect names, usernames, locations, subjects, and other short text information.
Example:
<form>
<label for="fullname">Full Name:</label>
<input type="text" id="fullname" name="fullname">
</form>Output: A text field where users can enter their full name.
You can also use attributes such as placeholder, maxlength, minlength, and required to control the input.
<input
type="text"
name="username"
placeholder="Enter your username"
minlength="3"
maxlength="20"
required
>The text input type is useful for registration forms, contact forms, and profile information.
2. HTML Password Input Type
The password input type creates a field where entered characters are visually hidden. It is commonly used for passwords, PINs, and other confidential text.
Example:
<form>
<label for="password">Password:</label>
<input type="password" id="password" name="password">
</form>When a user enters a password, the browser usually displays dots or other masking characters instead of the actual text.
You can specify a minimum and maximum password length.
<input
type="password"
name="password"
placeholder="Enter password"
minlength="8"
required
>Important: A password input only hides characters on the screen. It does not encrypt or securely transmit the password. Always use HTTPS and implement proper server-side password security.
3. HTML Email Input Type
The email input type allows users to enter an email address. Browsers provide built-in validation to check whether the entered value follows a basic email address format.
It is commonly used in registration forms, newsletter subscriptions, login pages, and contact forms.
Example:
<form>
<label for="email">Email Address:</label>
<input type="email" id="email" name="email">
</form>You can make the email field mandatory using the required attribute.
<input
type="email"
name="email"
placeholder="Enter your email"
required
>For multiple email addresses, you can use the multiple attribute.
<input type="email" name="emails" multiple>The browser checks the basic email format, but it cannot guarantee that the email address exists or belongs to the user.
4. HTML Number Input Type
The number input type allows users to enter numerical values. It is useful for quantities, ages, prices, product counts, and other numeric information.
Example:
<form>
<label for="age">Enter Your Age:</label>
<input type="number" id="age" name="age">
</form>You can control the minimum, maximum, and increment values using the min, max, and step attributes.
<input
type="number"
name="quantity"
min="1"
max="100"
step="1"
value="1"
>In this example:
min="1"sets the minimum value.max="100"sets the maximum value.step="1"specifies the increment.value="1"sets the initial value.
Note: The number input is intended for numerical quantities, not numeric-looking identifiers such as phone numbers, postal codes, or account numbers. Use tel or text for those values.
5. HTML Telephone Input Type
The tel input type is designed to collect telephone numbers. It may display a telephone-friendly keyboard on mobile devices.
Unlike the email and URL input types, the browser does not automatically validate a telephone number’s format because phone number formats vary across countries.
Example:
<form>
<label for="phone">Phone Number:</label>
<input type="tel" id="phone" name="phone">
</form>You can use the pattern attribute to define an expected format.
<input
type="tel"
name="phone"
placeholder="Enter 10-digit phone number"
pattern="[0-9]{10}"
maxlength="10"
required
>This example expects exactly 10 digits.
The telephone input type is useful for registration forms, contact pages, delivery information, and customer support forms.
6. HTML URL Input Type
The url input type allows users to enter a website address or URL. Browsers provide basic validation to check whether the entered value follows a valid URL format.
Example:
<form>
<label for="website">Website URL:</label>
<input type="url" id="website" name="website">
</form>You can also add a placeholder to guide users.
<input
type="url"
name="website"
placeholder="https://example.com"
>This input type is commonly used for website links, portfolio URLs, social media profiles, and business websites.
7. HTML Search Input Type
The search input type creates a field specifically designed for entering search queries. It is similar to the text input type but may receive special browser styling and behavior.
Example:
<form action="/search" method="get">
<label for="search">Search:</label>
<input type="search" id="search" name="q">
<button type="submit">Search</button>
</form>You can use a placeholder to explain what users should search for.
<input
type="search"
name="query"
placeholder="Search articles..."
>Search inputs are commonly used on blogs, e-commerce websites, documentation pages, and online learning platforms.
8. HTML Date Input Type
The date input type allows users to select a date using a browser-supported date picker.
It is useful for collecting birth dates, appointment dates, booking dates, and registration dates.
Example:
<form>
<label for="birthdate">Date of Birth:</label>
<input type="date" id="birthdate" name="birthdate">
</form>You can restrict the selectable date range using min and max.
<input
type="date"
name="appointment"
min="2026-01-01"
max="2026-12-31"
>The date value is generally submitted in the YYYY-MM-DD format, regardless of how the date is displayed to the user.
9. HTML Time Input Type
The time input type allows users to select a specific time, generally including hours and minutes.
It is useful for appointment scheduling, meeting arrangements, booking systems, and event registration.
Example:
<form>
<label for="meeting">Meeting Time:</label>
<input type="time" id="meeting" name="meeting">
</form>You can define a minimum and maximum selectable time.
<input
type="time"
name="meeting_time"
min="09:00"
max="18:00"
required
>The submitted time value generally follows the 24-hour format, such as 14:30.
10. HTML Datetime-Local Input Type
The datetime-local input type allows users to select both a date and a time without specifying a time zone.
It is useful for booking appointments, scheduling meetings, and selecting event dates.
Example:
<form>
<label for="event">Event Date and Time:</label>
<input
type="datetime-local"
id="event"
name="event"
>
</form>You can also specify minimum and maximum date-time values.
<input
type="datetime-local"
name="event_time"
min="2026-11-01T09:00"
max="2026-12-31T18:00"
>Unlike a time-zone-aware date-time value, datetime-local represents the local date and time selected by the user. Your application must handle time-zone interpretation when necessary.
11. HTML Month Input Type
The month input type allows users to select a particular month and year. It does not require users to choose a specific day.
It is useful for collecting billing months, subscription periods, monthly reports, and payment periods.
Example:
<form>
<label for="month">Select Month:</label>
<input type="month" id="month" name="month">
</form>You can also specify a minimum and maximum month.
<input
type="month"
name="billing_month"
min="2026-01"
max="2026-12"
>The submitted value generally follows the YYYY-MM format.
12. HTML Week Input Type
The week input type allows users to select a specific week of a year.
It is useful for weekly schedules, employee work reports, project planning, and weekly performance tracking.
Example:
<form>
<label for="week">Select Week:</label>
<input type="week" id="week" name="week">
</form>You can specify a minimum and maximum selectable week.
<input
type="week"
name="project_week"
min="2026-W01"
max="2026-W52"
>The submitted value follows the YYYY-Www format, where ww represents the week number.
13. HTML Checkbox Input Type
The checkbox input type creates a small selectable box that allows users to select one or multiple options.
Checkboxes are commonly used for terms and conditions, interests, preferences, and subscription choices.
Example:
<form>
<p>Select Your Interests:</p>
<input type="checkbox" id="html" name="interest" value="HTML">
<label for="html">HTML</label>
<input type="checkbox" id="css" name="interest" value="CSS">
<label for="css">CSS</label>
<input type="checkbox" id="js" name="interest" value="JavaScript">
<label for="js">JavaScript</label>
</form>Users can select multiple checkboxes at the same time.
You can use the checked attribute to select a checkbox by default.
<input type="checkbox" name="subscribe" value="yes" checked>Checkboxes are useful when users are allowed to select more than one option.
14. HTML Radio Input Type
The radio input type creates circular selection controls. It allows users to select only one option from a group of radio buttons that share the same name.
Radio buttons are commonly used for gender-neutral preference selections, payment methods, yes-or-no questions, and multiple-choice questions.
Example:
<form>
<p>Select Your Gender:</p>
<input type="radio" id="male" name="gender" value="Male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="Female">
<label for="female">Female</label>
<input type="radio" id="other" name="gender" value="Other">
<label for="other">Other</label>
</form>All radio buttons share the same name="gender", so only one option can be selected at a time.
You can select an option by default using the checked attribute.
<input type="radio" name="payment" value="cash" checked>15. HTML File Input Type
The file input type allows users to select and upload files from their devices.
It is commonly used for profile pictures, document submissions, resumes, photographs, and other attachments.
Example:
<form>
<label for="document">Upload Document:</label>
<input type="file" id="document" name="document">
</form>You can use the accept attribute to specify the types of files the browser should offer for selection.
<input
type="file"
name="image"
accept="image/*"
>To allow multiple file selections, use the multiple attribute.
<input
type="file"
name="documents"
multiple
>For an actual file upload, the form generally needs method="post" and enctype="multipart/form-data".
<form action="/upload" method="post" enctype="multipart/form-data">
<label for="resume">Upload Resume:</label>
<input type="file" id="resume" name="resume" accept=".pdf,.doc,.docx">
<button type="submit">Upload</button>
</form>Remember that the accept attribute is only a file-selection hint. The server must independently validate uploaded files, their size, and their contents.
16. HTML Color Input Type
The color input type creates a color picker that allows users to select a color.
It is useful for website customization, theme settings, graphic design tools, and user interface preferences.
Example:
<form>
<label for="color">Choose a Color:</label>
<input type="color" id="color" name="color" value="#0000ff">
</form>The value attribute sets the initial color.
You can also use the selected color with JavaScript to update a website element dynamically.
17. HTML Range Input Type
The range input type creates a slider that allows users to select a numerical value within a specified range.
It is useful for volume controls, brightness settings, product filters, ratings, and price selection.
Example:
<form>
<label for="volume">Volume:</label>
<input
type="range"
id="volume"
name="volume"
min="0"
max="100"
value="50"
>
</form>In this example:
min="0"defines the minimum value.max="100"defines the maximum value.value="50"sets the initial slider position.
You can use the step attribute to control the interval between selectable values.
<input type="range" min="0" max="100" step="10" value="50">18. HTML Hidden Input Type
The hidden input type stores data in a form without displaying a visible input field to users.
It is useful for passing record IDs, form-related values, and other information that the application needs during form submission.
Example:
<form action="/submit" method="post">
<input type="hidden" name="user_id" value="12345">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<button type="submit">Submit</button>
</form>The hidden input is not displayed on the webpage, but its value is included when the form is submitted.
Important: Hidden inputs are not secure storage. Users can inspect and modify their values through browser developer tools. Never trust hidden input values for authorization, authentication, or sensitive information.
19. HTML Submit Input Type
The submit input type creates a button that submits the form when clicked.
It is commonly used in login forms, registration pages, contact forms, and online applications.
Example:
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<input type="submit" value="Submit Form">
</form>The value attribute specifies the text displayed on the submit button.
You can also use the <button type="submit"> element to create a submit button with more flexible content and styling.
20. HTML Reset Input Type
The reset input type creates a button that restores form controls to their initial values.
It is useful when users need to clear their changes and start filling out a form again.
Example:
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" value="John">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<input type="reset" value="Reset Form">
</form>When users click the reset button, the form controls return to their original values. It does not necessarily clear every field; controls with predefined values return to those values.
21. HTML Button Input Type
The button input type creates a clickable button that does not automatically submit or reset a form.
It is generally used with JavaScript to perform custom actions.
Example:
<form>
<input
type="button"
value="Click Me"
onclick="alert('Welcome to HTML!')"
>
</form>When users click the button, the JavaScript code displays an alert message.
For most modern projects, the <button type="button"> element is a more flexible alternative.
22. HTML Image Input Type
The image input type creates a graphical submit button using an image.
It works like a submit button but displays an image instead of ordinary button text.
Example:
<form action="/submit" method="post">
<input
type="image"
src="submit-button.png"
alt="Submit Form"
width="120"
height="40"
>
</form>The src attribute specifies the image file, while alt provides alternative text.
When clicked, the image input submits the form. Browsers can also include the click coordinates in the submitted form data.
Important HTML Input Attributes
HTML input attributes help control the behavior, appearance, and validation of input elements. They make forms more interactive and user-friendly.
Here are some important attributes you should understand.
| Attribute | Description | Example |
|---|---|---|
type | Specifies the input type. | type="email" |
name | Defines the submitted field name. | name="username" |
id | Provides a unique element identifier. | id="email" |
value | Sets the initial value. | value="John" |
placeholder | Displays a short hint. | placeholder="Enter name" |
required | Makes the field mandatory. | required |
readonly | Prevents users from editing the value. | readonly |
disabled | Disables the input field. | disabled |
maxlength | Sets the maximum text length. | maxlength="20" |
minlength | Sets the minimum text length. | minlength="5" |
min | Sets the minimum permitted value. | min="1" |
max | Sets the maximum permitted value. | max="100" |
step | Defines the allowed value interval. | step="5" |
pattern | Specifies a validation pattern. | pattern="[0-9]{10}" |
multiple | Allows multiple values or files where supported. | multiple |
checked | Selects a checkbox or radio button initially. | checked |
autocomplete | Controls browser autocomplete behavior. | autocomplete="email" |
autofocus | Automatically focuses the input when appropriate. | autofocus |
accept | Suggests acceptable file types. | accept=".pdf" |
list | Connects an input to a datalist. | list="suggestions" |
form | Associates an input with a form by ID. | form="myForm" |
Example Using Multiple Input Attributes
The following example demonstrates how different attributes can be combined to create a useful input field.
<form>
<label for="username">Username:</label>
<input
type="text"
id="username"
name="username"
placeholder="Enter your username"
minlength="3"
maxlength="20"
autocomplete="username"
required
>
<button type="submit">Register</button>
</form>In this example, the user must enter a username containing at least three characters and no more than 20 characters before submitting the form.
HTML Input Types: Complete Practical Example
Now that you understand the different input types, let’s create a practical HTML registration form using several of them together.
This example includes text, email, password, telephone, number, date, radio, checkbox, file, and submit input types.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Registration Form</title>
</head>
<body>
<h2>Registration Form</h2>
<form action="/register" method="post" enctype="multipart/form-data">
<label for="fullname">Full Name:</label>
<input type="text" id="fullname" name="fullname" required>
<br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" minlength="8" required>
<br><br>
<label for="phone">Phone Number:</label>
<input type="tel" id="phone" name="phone">
<br><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age" min="18" max="100">
<br><br>
<label for="dob">Date of Birth:</label>
<input type="date" id="dob" name="dob">
<br><br>
<p>Gender:</p>
<input type="radio" id="male" name="gender" value="Male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="Female">
<label for="female">Female</label>
<input type="radio" id="other" name="gender" value="Other">
<label for="other">Other</label>
<br><br>
<p>Choose Your Interests:</p>
<input type="checkbox" id="html" name="interests[]" value="HTML">
<label for="html">HTML</label>
<input type="checkbox" id="css" name="interests[]" value="CSS">
<label for="css">CSS</label>
<input type="checkbox" id="javascript" name="interests[]" value="JavaScript">
<label for="javascript">JavaScript</label>
<br><br>
<label for="photo">Upload Profile Photo:</label>
<input type="file" id="photo" name="photo" accept="image/*">
<br><br>
<input type="checkbox" id="terms" name="terms" value="accepted" required>
<label for="terms">I agree to the terms and conditions.</label>
<br><br>
<input type="submit" value="Register">
<input type="reset" value="Clear Form">
</form>
</body>
</html>This example demonstrates how multiple HTML input types can work together to collect different kinds of user information.
The form provides basic browser validation, but a complete registration system also requires server-side validation, secure password handling, and appropriate file-upload processing.
Difference Between Text, Email, Number, and Password Input Types
Although these input types may look similar, they serve different purposes.
| Feature | Text | Number | Password | |
|---|---|---|---|---|
| Accepts text | Yes | Yes, in email format | No, intended for numbers | Yes |
| Hides characters | No | No | No | Yes |
| Built-in format validation | No | Yes | Numeric constraints | No password-strength validation |
| Common use | Names | Email addresses | Quantities | Passwords |
| Mobile keyboard | General text | Often email-friendly | Often numeric | Often password-friendly |
Choosing the correct input type helps browsers provide suitable keyboards, controls, and validation behavior.
Difference Between Checkbox and Radio Input Types
Checkboxes and radio buttons are both used to select options, but their selection behavior is different.
| Feature | Checkbox | Radio |
|---|---|---|
| Shape | Square by default | Circular by default |
| Selection | Multiple options | One option per group |
| Main purpose | Multiple selections | Single selection |
| HTML type | checkbox | radio |
| Common example | Interests | Payment method |
Checkbox example:
<input type="checkbox" name="hobby" value="Reading">
<input type="checkbox" name="hobby" value="Gaming">
<input type="checkbox" name="hobby" value="Traveling">Users can select all three options.
Radio example:
<input type="radio" name="payment" value="Cash">
<input type="radio" name="payment" value="Card">
<input type="radio" name="payment" value="UPI">Users can select only one option from the group.
HTML Input Validation
HTML provides built-in form validation features that help prevent users from submitting incorrectly formatted information.
You can use different attributes to validate input values without writing JavaScript.
Required Attribute
The required attribute makes an input field mandatory.
<input type="text" name="username" required>Users cannot submit the form normally without providing a value.
Min and Max Attributes
The min and max attributes define the acceptable numerical or date range for supported input types.
<input type="number" name="age" min="18" max="60">This example allows values from 18 to 60.
Minlength and Maxlength Attributes
These attributes define the minimum and maximum number of characters for text-like input fields.
<input type="text" name="username" minlength="3" maxlength="15">Pattern Attribute
The pattern attribute allows you to specify a regular expression that the input value must match.
<input
type="text"
name="pincode"
pattern="[0-9]{6}"
placeholder="Enter 6-digit PIN code"
required
>This example expects exactly six digits.
Step Attribute
The step attribute controls the permitted intervals for numerical and date/time values where supported.
<input type="number" name="price" min="0" step="0.5">This allows values such as 10, 10.5, and 11.
Important: Browser validation improves the user experience but should never replace server-side validation. Data submitted to a server must always be checked independently.
Best Practices for Using HTML Input Types
When building HTML forms, following good practices can make your website more accessible, reliable, and user-friendly.
- Choose the correct input type: Use email for email addresses, password for passwords, date for dates, and number for numerical quantities.
- Always use labels: Connect each input field with a meaningful
<label>element using matchingforandidvalues. - Use placeholder text carefully: Placeholders should provide examples or short hints rather than replace labels.
- Make important fields required: Use the
requiredattribute for information that users must provide. - Use appropriate autocomplete values: Attributes such as
autocomplete="name",autocomplete="email", andautocomplete="tel"can make form completion easier. - Validate information on the server: Never rely exclusively on HTML validation because users can bypass browser-side restrictions.
- Use field grouping: Use
<fieldset>and<legend>to group related form controls, particularly radio buttons and checkboxes. - Provide clear error messages: Explain what information is incorrect and how users can fix it.
- Consider mobile users: Select suitable input types to help mobile browsers display appropriate keyboards and controls.
- Protect sensitive information: Use HTTPS, secure authentication practices, and proper server-side handling for passwords and personal information.
Frequently Asked Questions (FAQs)
1. What are HTML input types?
HTML input types define the type of information users can enter or select in an HTML form. They are specified using the type attribute of the <input> element. Examples include text, email, password, number, date, checkbox, radio, and file.
2. How many input types are available in HTML?
HTML provides 22 commonly recognized input types: text, password, email, number, tel, url, search, date, time, datetime-local, month, week, checkbox, radio, file, color, range, hidden, submit, reset, button, and image.
3. What is the difference between text and email input types?
The text input type accepts general single-line text without built-in format validation. The email input type is designed for email addresses and provides basic browser validation to check whether the entered value follows an acceptable email format.
4. Which HTML input type is used for passwords?
The password input type is used to collect passwords. It visually masks entered characters, making the password less visible while users type.
5. Which HTML input type is used to upload files?
The file input type allows users to select files from their devices. You can use the accept attribute to suggest specific file formats and the multiple attribute to allow multiple file selections.
6. What is the difference between checkbox and radio buttons?
Checkboxes allow users to select multiple options, while radio buttons allow users to select only one option from a group of buttons that share the same name.
7. What is the purpose of the HTML number input type?
The number input type allows users to enter numerical values. It supports attributes such as min, max, and step to control the permitted range and increments.
8. Can HTML input types validate user information?
Yes. HTML input types and attributes such as required, pattern, min, max, minlength, and maxlength provide built-in browser validation. However, server-side validation is still necessary for security and data accuracy.
9. What is the difference between hidden and disabled input fields?
A hidden input is not displayed on the webpage but its value is generally submitted with the form. A disabled input is visible in most cases but cannot be edited, and its value is not included in normal form submission.
10. Which HTML input type is used for selecting dates?
The date input type allows users to select a date using a browser-supported date picker. Other date and time-related input types include time, datetime-local, month, and week.
Conclusion
HTML input types are fundamental elements of web forms. They make it possible to collect different kinds of information through simple and interactive form controls.
From basic text fields and password inputs to date pickers, file uploads, checkboxes, radio buttons, and range sliders, each input type serves a specific purpose.
By understanding the available input types, their attributes, and validation features, you can create more effective forms for websites and web applications.
If you are learning HTML, practice using these input types by building registration forms, login pages, contact forms, search boxes, and booking forms. Practical experience will help you understand how HTML forms work and prepare you for more advanced web development concepts.