Input Type Validation
You'll learn: How HTML5 input types automatically enforce format rules without writing any JavaScript validation code.
What Is Input Type Validation?
When you use specific HTML5 input types like email, url, or number, the browser automatically validates that the user's input matches the expected format. This is built-in validation that happens before the form even tries to submit — no extra code required on your part.
Think of it like ordering at a restaurant with a picture menu: the waiter can immediately tell if you're pointing at a drink or a dessert. Similarly, an <input type="email"> immediately knows whether what you typed looks like an email address.
How It Works
Instead of using <input type="text"> for everything, you specify the data type you expect:
<input type="email" name="userEmail" required>
<input type="url" name="website" required>
<input type="number" name="age" required>
When a user tries to submit:
type="email"checks for an@symbol and basic email structuretype="url"verifies a valid URL format (likehttps://example.com)type="number"ensures only numeric input (often with spinner controls)
If the format doesn't match, the browser shows an error message and prevents submission — all without you writing validation logic.
Why This Matters
This automatic validation provides an instant user experience improvement and reduces the JavaScript you need to write. It also gives mobile users appropriate keyboards (numeric keypad for number, email keyboard for email).
Key Takeaway: Using semantic input types like email, url, and number gives you free, automatic format validation from the browser itself.