HTML5 Form Validation
HTML
What is HTML5 Form Validation?
HTML5 brought built-in client-side validation to forms.
It means the browser itself checks user input before submitting the form, without JavaScript.
It ensures:
- Required fields are filled.
- Input matches expected types (email, URL, etc).
- Length, patterns, ranges are respected.
Common HTML5 validation features
1️. required
Makes a field mandatory.
If left empty, the browser shows: “Please fill out this field.”
2️. type validation
Certain types like email, url, number auto-validate.
If you enter abc
, it will warn: “Please include an '@' in the email address.”
3️. min and max
For number/date range checks.
4️. minlength and maxlength
Set allowed string length.
5️. pattern
Use regex to enforce a custom format.
If input doesn’t match pattern, it shows the title
as tooltip.
6️. step
Controls steps for numbers.
Only accepts 0
, 2
, 4
, 6
, 8
, 10
.
7️. placeholder
Not validation, but helps guide expected input.
8️. novalidate
Turn off browser validation for a form.
Example: A complete validated form
Try submitting this with missing or invalid data — the browser itself will block submission and show helpful messages.