HTML Form Validation Without JavaScript
HTML5 has built-in form validation: required fields, length and number limits, and format patterns, all without a single line of JavaScript.
- Reading time
- 1 min read
- Comments
- Discussion

On this page
Required Fields
<input type="text" name="name" required />
The browser will stop the form from submitting if this field is empty.
Text Length Limits
<input type="text" name="username" minlength="3" maxlength="20" required />
Number Limits
<input type="number" name="age" min="18" max="99" required />
Pattern (Custom Format)
<input type="text" name="zip" pattern="[0-9]{5}" placeholder="12345" required />
This example only allows exactly 5 digits.
Email and URL Validation
<input type="email" name="email" required /> <input type="url" name="website" />
The browser automatically checks if the format looks correct.
Common Validation Attributes
| Attribute | Purpose |
|---|---|
| required | Field must be filled |
| minlength | Minimum number of characters |
| maxlength | Maximum number of characters |
| min | Minimum number value |
| max | Maximum number value |
| pattern | Custom format using regular expression |
| type=“email” | Checks for a valid email format |
| type=“url” | Checks for a valid URL format |
Quick Tips
- Built-in validation improves user experience, but it’s not fully secure, always validate again on the server.
- Clear labels help users understand what went wrong.
- Keep pattern simple so it’s easy to maintain.
- Test your form in different browsers, because validation messages can look slightly different.
- With these HTML features, you can already make your forms much better before adding any JavaScript.

Written by
Razak
Writes about the web, slowly, and builds small tools on the side.
Keep reading
Read next
1 minBest Practices for Writing Clean and Valid HTML
A collection of HTML best practices including proper indentation, naming, W3C validation, and common beginner mistakes you should avoid.
Read article
2 minGetting to Know HTML Iframe: How to Embed YouTube and Google Maps
How to use the HTML <iframe> tag to embed content from other sites, like a YouTube video or a Google Map, inside your own page.
Read article
1 minHow to Create Forms in HTML for Beginners
A beginner's guide to HTML forms: how the <form> tag sends data for logins, sign-ups and contact messages, starting from the basics.
Read article
Discussion
Comments
Loading comments…