Forms & Inputs
Forms collect user input
<form action="/signup" method="post">
<label for="email">Email</label>
<input id="email" name="email" type="email" required>
<button type="submit">Sign up</button>
</form>
actionis where data is sent;methodisgetorpost.nameis the key the server receives.- Always connect a
<label>to each input withforandid. Tapping the label focuses the field, and screen readers announce it.
Input types (the right one gives the right phone keyboard)
| Type | Use |
|---|---|
text, email, password, tel, url | text fields |
number, range | numbers |
date, time | pickers |
checkbox, radio | choices |
file | uploads |
Plus <textarea> for long text and <select> with <option> for dropdowns. |
Built-in validation
required, minlength, maxlength, min, max, pattern="[0-9]{10}", and type="email". The browser blocks submission and shows a message.
⚠️ Browser validation is for user experience only. Always validate again on the server, because anyone can bypass the browser.
Useful attributes
placeholder (a hint, never a replacement for a label), autocomplete="email", disabled, readonly, value.
Example
<form onsubmit="event.preventDefault(); alert('Thanks, ' + this.name.value + '!')">
<p>
<label for="name">Name</label><br />
<input id="name" name="name" required minlength="2" autocomplete="name" />
</p>
<p>
<label for="email">Email</label><br />
<input id="email" name="email" type="email" required autocomplete="email" />
</p>
<p>
<label for="level">Level</label><br />
<select id="level" name="level">
<option>Beginner</option>
<option>Intermediate</option>
</select>
</p>
<p>
<label><input type="checkbox" name="news" /> Send me updates</label>
</p>
<button type="submit">Join</button>
</form>