Input types help users enter different kinds of information easily and correctly on a webpage.
Input types (text, email, password, number) in HTML
<input type="text" name="exampleText"> <input type="email" name="exampleEmail"> <input type="password" name="examplePassword"> <input type="number" name="exampleNumber">
<input type="text" placeholder="Enter your name">
<input type="email" placeholder="Enter your email">
<input type="password" placeholder="Enter your password">
<input type="number" placeholder="Enter your age" min="1" max="120">
This webpage shows four input boxes for text, email, password, and number. Each input has a label and placeholder text to guide the user. The number input limits age between 1 and 120. The form uses simple styling for clarity and accessibility.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Input Types Example</title> <style> body { font-family: Arial, sans-serif; padding: 1rem; max-width: 400px; margin: auto; } label { display: block; margin-top: 1rem; font-weight: 600; } input { width: 100%; padding: 0.5rem; margin-top: 0.25rem; font-size: 1rem; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } </style> </head> <body> <h1>Input Types Demo</h1> <form> <label for="name">Name (text):</label> <input type="text" id="name" name="name" placeholder="Enter your name" required> <label for="email">Email (email):</label> <input type="email" id="email" name="email" placeholder="Enter your email" required> <label for="password">Password (password):</label> <input type="password" id="password" name="password" placeholder="Enter your password" required> <label for="age">Age (number):</label> <input type="number" id="age" name="age" placeholder="Enter your age" min="1" max="120" required> <button type="submit" style="margin-top:1rem; padding:0.5rem 1rem; font-size:1rem;">Submit</button> </form> </body> </html>
Using the right input type helps users and browsers understand what kind of data is expected.
On mobile devices, input types like email and number show keyboards suited for those inputs.
Always use labels for inputs to improve accessibility for screen readers.
Input types define what kind of information users can enter.
Common types are text, email, password, and number.
Using correct input types improves user experience and accessibility.
Practice
input type should you use to let users enter their email address?Solution
Step 1: Understand the purpose of input types
Theemailinput type is designed specifically to accept email addresses and validate their format.Step 2: Match input type to data
Since the question asks for an input type for email addresses,emailis the correct choice.Final Answer:
email -> Option CQuick Check:
Email input type = email [OK]
email type for email inputs to get validation [OK]- Using
textinstead ofemailloses validation - Choosing
passwordhides input unnecessarily - Using
numberfor emails is invalid
Solution
Step 1: Recall correct input type attribute
The correct attribute for password fields istype='password'.Step 2: Check each option's syntax
Only<input type='password'>uses the correct attribute and syntax for a password input.Final Answer:
<input type='password'> -> Option AQuick Check:
Password input syntax = <input type='password'> [OK]
- Omitting type attribute
- Using incorrect type names like 'pass' or 'text-password'
- Writing without type
<input type='number' id='age' name='age'>
Solution
Step 1: Understand
Thenumberinput behaviornumberinput only accepts numeric values and shows an error if invalid input is entered.Step 2: Predict browser validation
If letters are typed, the browser will prevent form submission and show a validation error.Final Answer:
Show an error and prevent form submission -> Option BQuick Check:
Number input blocks letters = error shown [OK]
- Thinking letters are accepted silently
- Assuming automatic conversion to numbers
- Believing input is ignored without error
<input type='email' name='user_email' placeholder='Enter email'> <input type='number' name='age' min='0' max='100'> <input type='password' name='pass'> <input type='text' name='username' required='false'>
Solution
Step 1: Review the
Therequiredattribute usagerequiredattribute is a boolean attribute and should not have a value like 'false'. It is either present or absent.Step 2: Check other attributes
minandmaxare valid for number inputs,placeholderis valid for email, andtype='password'is present.Final Answer:
Therequiredattribute cannot have a value -> Option AQuick Check:
Boolean attributes have no value = Therequiredattribute cannot have a value [OK]
- Setting required='false' instead of removing attribute
- Thinking min/max are invalid on number inputs
- Confusing placeholder usage on email inputs
- Accepts only numbers between 1 and 10
- Shows a placeholder "Enter a number"
- Is required to submit the form
Which is the correct HTML code?
Solution
Step 1: Choose input type for numbers
Usetype='number'to accept only numeric input.Step 2: Set min, max, placeholder, and required correctly
Setmin='1'andmax='10'to limit range, addplaceholdertext, and userequiredas a boolean attribute without value.Step 3: Verify options
<input type='number' min='1' max='10' placeholder='Enter a number' required>matches all requirements correctly. The version usingtype='text'allows non-numeric input, the one withrequired='false'misuses the required attribute, and the simplest version lacks range limits and the required attribute.Final Answer:
<input type='number' min='1' max='10' placeholder='Enter a number' required> -> Option DQuick Check:
Number input with min, max, placeholder, required =<input type='number' min='1' max='10' placeholder='Enter a number' required>[OK]
- Using type='text' for numbers
- Setting required='false' instead of removing attribute
- Omitting min and max for number limits
Ready to prove it?
Pass the test and this pattern moves unknown
