CHAPTER 32 · HTML
Input types: choose a field that matches the information
Text, email addresses and passwords can look similar on a page, but their controls have different purposes. Learn the input-type families, then practise useful text fields without pretending that a field alone provides search or login.
Download example files (ZIP)One element, several kinds of control
A map of the input types
Text and search
<label for="query">Topic to find</label>
<input type="search" id="query" name="q" value="HTML lists">- 1Text or search: a general line or query
- 2Email and URL: useful native format checks
- 3Tel: purpose and possible keypad hints
- 4Password: display masking only
An input type does not create search, login or verification services.
Complete program: topic-search.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>A Search Field Practice Page</title>
</head>
<body>
<h1>Describe a topic search</h1>
<p>This sends a practice query to the local destination; it does not search a catalogue.</p>
<form action="form-result.html" method="get">
<p><label for="query">Topic to find</label></p>
<p><input type="search" id="query" name="q" value="HTML lists" size="24"></p>
<button type="submit">Inspect the query</button>
</form>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. Form submission is disabled in this preview. Save the example and its result page locally to test submission. Use fictional practice values.
Email, URL and telephone
<label for="practice-email">Fictional contact email</label>
<input type="email" id="practice-email" name="email" placeholder="learner@example.com">Complete program: contact-fields.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Choose Suitable Contact Inputs</title>
</head>
<body>
<h1>Try fictional contact values</h1>
<p>Use invented details. This exercise creates no account and stores no contact record.</p>
<form action="form-result.html" method="get">
<p><label for="display-name">Practice display name</label></p>
<p><input type="text" id="display-name" name="display_name" autocomplete="nickname"></p>
<p><label for="practice-email">Fictional email</label></p>
<p><input type="email" id="practice-email" name="email" placeholder="learner@example.com"></p>
<p><label for="practice-site">Example website address</label></p>
<p><input type="url" id="practice-site" name="website" placeholder="https://example.com"></p>
<p><label for="practice-phone">Invented phone value</label></p>
<p><input type="tel" id="practice-phone" name="phone"></p>
<button type="submit">Inspect these practice values</button>
</form>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. Form submission is disabled in this preview. Save the example and its result page locally to test submission. Use fictional practice values.
Password masking is not encryption
<label for="demo-password">Invented password text for display practice</label>
<input type="password" id="demo-password" autocomplete="new-password">Autocomplete and keyboard hints
Hidden fields are still client data
Problem and solution: a phone field accepts letters
Common mistakes and useful tips
Assuming search creates search results or password creates login. Using placeholder as the field's only label. Treating email validity as ownership verification. Using number for every digit-containing identifier. Treating inputmode as validation. Believing hidden means confidential or tamper-proof. Expecting the same native keyboard and decoration on every device.
Practice questions
What happens when an input type is omitted or unrecognised? Does type="search" create a search service? What does an email type check fail to prove? Why is a placeholder not a sufficient field label? How does inputmode differ from input type? Save contact-fields.html and its local destination. Try empty optional fields, malformed email text and a fictional well-formed value. Explain which behaviour comes from the browser and which would need an application.
Check your practice answers
The control generally uses the text state. No. It describes a search-entry control; a receiving application must implement searching. It does not prove existence, deliverability or ownership. It disappears after entry and does not replace a persistent accessible name and instructions. Type selects a control's state and behaviour. Inputmode suggests a keyboard layout without enforcing a value rule. Empty optional email values can be valid; malformed non-empty values can fail the type check. The local destination still does not verify addresses, save contacts or create an account.
Interview questions
When would a digit-based value still use text input?
What does password input protect by itself?
Can a hidden field be trusted more than a visible field?
Do keyboard hints enforce a format?
Quick revision
Choose input types by the information's purpose. Native checks and keyboards help but do not create application features. Keep visible labels and use placeholders only for supplementary examples. Password masking and hidden fields are not security systems.