HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

HTML Tutorial

HTML Basics

Introduction to HTMLHTML EditorsHTML StructureHTML Elements & AttributesHTML HeadingsHTML ParagraphsHTML FormattingHTML CommentsHTML Styles

HTML Text and Links

HTML Text FormattingHTML Quotations & CitationsHTML LinksHTML Email Links

HTML Lists and Tables

HTML ListsHTML TablesTable Styling & Borders

HTML Images and Media

HTML ImagesHTML Picture ElementHTML AudioHTML VideoHTML Embed & Object

HTML Forms

HTML Forms OverviewHTML Form ElementsHTML Input TypesHTML Input AttributesHTML Form AttributesHTML Form Validation

HTML Layout

HTML Block vs Inline ElementsHTML Div & SpanHTML Semantic Layout TagsHTML Iframes

Advanced HTML

HTML Entities & SymbolsHTML EmojisHTML Head Element TagsHTML Meta Tags for SEOHTML Responsive Design

HTML References

HTML5 New TagsDeprecated TagsHTML Global AttributesEvent AttributesComplete HTML Tag ListComplete HTML5 ElementsHTML Tutorial PDF
  1. Home
  2. /
  3. Tutorials
  4. /
  5. HTML Tutorial
  6. /
  7. HTML Form Validation

HTML Forms

HTML Form Validation

Form validation ensures that the data entered by a user meets the expected format and requirements before being submitted to the server. It helps maintain data accuracy, prevent errors, and enhance user experience.

HTML5 introduced built-in form validation features that work without the need for JavaScript.

What is Form Validation?

Form validation checks if the form fields are filled out correctly.
It can be of two types:

  • Client-side validation – Performed by the browser using HTML5 attributes.
  • Server-side validation – Performed by the server after submission (for extra security).

HTML5’s client-side validation is fast and prevents invalid data from being sent.

The required Attribute

Specifies that an input field must be filled before submitting the form.

Required Example

html

<form>
  <label>Email:</label>
  <input type="email" name="email" required>
  <input type="submit" value="Submit">
</form>

If the user tries to submit without filling the field, the browser shows an error message.

The pattern Attribute

Defines a regular expression pattern that the input value must match.

Pattern Example

html

<form>
  <label>Username (letters only):</label>
  <input type="text" name="username" pattern="[A-Za-z]+" required>
  <input type="submit" value="Submit">
</form>

This ensures only alphabetic characters are allowed.

The min and max Attributes

Used for numeric and date inputs to specify minimum and maximum allowed values.

Min and Max Example

html

<form>
  <label>Age (18–60):</label>
  <input type="number" name="age" min="18" max="60" required>
  <input type="submit" value="Submit">
</form>

The step Attribute

Specifies the allowed intervals for numeric input.

Step Example

html

<form>
  <label>Enter number (increments of 5):</label>
  <input type="number" name="quantity" step="5">
  <input type="submit">
</form>

The type Attribute and Validation

HTML input types such as email, url, and number automatically validate data.

Type Example

html

<form>
  <label>Email:</label>
  <input type="email" name="email" required><br><br>

  <label>Website:</label>
  <input type="url" name="website" required><br><br>

  <input type="submit">
</form>

If the entered text is not a valid email or URL, the browser displays an error.

The novalidate Attribute (Disable Validation)

You can disable form validation entirely using the novalidate attribute in the <form> tag.

Novalidate Example

html

<form novalidate>
  <input type="email" name="email" placeholder="Enter email">
  <input type="submit">
</form>

This is useful for testing or when you want to handle validation using JavaScript.

Using title to Display a Custom Message

When using the pattern attribute, you can use title to show a custom error hint.

Custom Message Example

html

<form>
  <label>Username:</label>
  <input type="text" name="username" pattern="[A-Za-z]+" title="Only letters are allowed">
  <input type="submit">
</form>

Complete Form Validation

Example

html

<form action="/samples/form_processor.php" method="post">
  <label>Full Name:</label>
  <input type="text" name="fullname" required><br><br>

  <label>Email:</label>
  <input type="email" name="email" required><br><br>

  <label>Age (18–60):</label>
  <input type="number" name="age" min="18" max="60" required><br><br>

  <label>Password:</label>
  <input type="password" name="password" minlength="6" maxlength="12" required><br><br>

  <label>Website:</label>
  <input type="url" name="website" required><br><br>

  <input type="submit" value="Submit Form">
</form>

If the user leaves any required field blank or enters invalid data, the browser automatically prevents submission and shows relevant hints.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

Conclusion

HTML form validation is a powerful feature that improves data accuracy and user experience without extra JavaScript.
Using attributes like required, pattern, min, max, and input types such as email or url, you can easily ensure correct and complete data entry.

PreviousHTML Form AttributesNextHTML Block vs Inline Elements