27. Input types
Module 6 · About 20 minutes · Lesson 26; review earlier concepts as needed
Open Interactive LessonDiscover
What changes when you use input types, and how can you prove it?
- Explain input types using the example source
- Predict the visual or structural effect of one controlled change
- Repair the supplied fault and verify actual output
Predict
Record the expected structure or visual change before rendering. Name one thing that should remain unchanged.
Understand
Input types communicate the expected data and can affect native keyboards, validation and widgets. type=email performs syntax checking but does not verify that a mailbox exists. Number inputs are suitable for quantities rather than identifiers such as postal codes. Give each control a meaningful name and visible label, and test the browser’s actual behavior.
Important source lines
- index.html:1 <form><label>Email <input type="email" name="email" autocomplete="email" required></label><label>Seats <input type="number" name="seats" min="1" max="6" value="1"></label><button>Preview</button></form>
- A group of named controls for a submitted task. Attribute guidance: action/method for real delivery; local preview intercepts submission.
- styles.css:1 label { display:block; margin:1rem 0; }
- Selects outer/inner display behavior; Grid establishes a layout context. Accepted grammar: [ <display-outside> || <display-inside> ] | <display-listitem> | <display-internal> | <display-box> | <display-legacy>. Context: block.
The first example teaches this lesson’s primary contract. Additional examples are optional related references or applications, each with its own purpose and source; an example without an authored check requires the stated visual/manual review.
Example 1: Input types
The email control exposes native email syntax validation; seats are constrained numeric quantities.
index.html
<form><label>Email <input type="email" name="email" autocomplete="email" required></label><label>Seats <input type="number" name="seats" min="1" max="6" value="1"></label><button>Preview</button></form>
styles.css
label { display:block; margin:1rem 0; }script.js
Expected: The email control exposes native email syntax validation; seats are constrained numeric quantities.
Edit and Render This ExampleExample 2: Element: form
A group of named controls for a submitted task.
index.html
<form><label>Name <input name="name" required></label><button>Preview locally</button></form><p>Delivery needs a configured backend.</p>
styles.css
body { font:18px/1.6 system-ui; margin:1.5rem; color:#17324d; } img,video,svg { max-width:100%; height:auto; } th,td { padding:.5rem; border:1px solid #a8b8c8; } :focus-visible { outline:3px solid #a44322; outline-offset:3px; }script.js
Expected: A group of named controls for a submitted task. Review its real DOM and native behavior; structural/media-only examples are labeled.
Edit and Render This ExampleExample 3: Element: label
A visible programmatic name for a control.
index.html
<label for="email">Email</label><input id="email" name="email" type="email">
styles.css
body { font:18px/1.6 system-ui; margin:1.5rem; color:#17324d; } img,video,svg { max-width:100%; height:auto; } th,td { padding:.5rem; border:1px solid #a8b8c8; } :focus-visible { outline:3px solid #a44322; outline-offset:3px; }script.js
Expected: A visible programmatic name for a control. Review its real DOM and native behavior; structural/media-only examples are labeled.
Edit and Render This ExampleExample 4: Element: input
A native control whose type selects a data/interaction contract.
index.html
<label>Quantity <input type="number" name="quantity" min="1" max="6" value="1"></label>
styles.css
body { font:18px/1.6 system-ui; margin:1.5rem; color:#17324d; } img,video,svg { max-width:100%; height:auto; } th,td { padding:.5rem; border:1px solid #a8b8c8; } :focus-visible { outline:3px solid #a44322; outline-offset:3px; }script.js
Expected: A native control whose type selects a data/interaction contract. Review its real DOM and native behavior; structural/media-only examples are labeled.
Edit and Render This ExampleExample 5: Element: button
A native action control with keyboard behavior.
index.html
<form><label>Name <input name="name" required></label><button type="submit">Preview</button><button type="reset">Reset fields</button></form>
styles.css
body { font:18px/1.6 system-ui; margin:1.5rem; color:#17324d; } img,video,svg { max-width:100%; height:auto; } th,td { padding:.5rem; border:1px solid #a8b8c8; } :focus-visible { outline:3px solid #a44322; outline-offset:3px; }script.js
Expected: A native action control with keyboard behavior. Review its real DOM and native behavior; structural/media-only examples are labeled.
Edit and Render This ExampleBuild and test
The email control exposes native email syntax validation; seats are constrained numeric quantities. Repair the current exercise without removing necessary content. Checks inspect the stated structural/computed/stylesheet contract, not exact source text.
Starter index.html
<form><label>Email <input type="text" name="email" autocomplete="email" required></label><label>Seats <input type="number" name="seats" min="1" max="6" value="1"></label><button>Preview</button></form>
Starter styles.css
label { display:block; margin:1rem 0; }Objective contract
[
{
"type": "attr",
"selector": "input[name=\"email\"]",
"property": "type",
"value": "email",
"label": "input[name=\"email\"] has type=email"
}
]Hint 1
Locate the first difference between the intended result and the real preview. Inspect matching elements and computed styles.
Hint 2
The relevant source uses type="email". The exercise instead uses type="text". Identify its effect before changing it.
Hint 3
Restore the intended type="email" operation or implement an equivalent structure/style. Run the actual checks and explain why it works.
Complete reference solution
index.html
<form><label>Email <input type="email" name="email" autocomplete="email" required></label><label>Seats <input type="number" name="seats" min="1" max="6" value="1"></label><button>Preview</button></form>
styles.css
label { display:block; margin:1rem 0; }Explain, reflect and extend
Which part of the actual preview or inspector proves this result? Explain one boundary case and name what automated checks do not verify.
Apply this concept to a different realistic piece of content. Predict its structure or visual behavior, test narrow and wide widths where relevant, then record one invalid case and its repair.
Troubleshooting and professional practice
If nothing changes, confirm that you edited the active file and ran Run Preview, or enabled Auto Preview. Inspect the actual DOM because the browser may repair invalid nesting. For CSS, check selector matches, valid declarations, active queries and computed values. Preserve local asset paths and inspect warnings. The email control exposes native email syntax validation; seats are constrained numeric quantities.
Knowledge check
Explain why the stated result follows from the source. Predict a second input or width and test it independently. Automated contracts and written explanations are reviewed separately.
Optional AI prompts
- Explain this lesson’s source line by line using the actual objective above.
- Help implement one small extension and define normal, boundary and failure tests.
- Review/debug the source against actual preview observations; verify standards and never claim rendering without evidence.