SyntaxStudy
Sign Up
HTML Form Validation Attributes
HTML Beginner 1 min read

Form Validation Attributes

Form Validation Attributes

HTML5 added built-in validation that the browser handles automatically — no JavaScript required.

Validation Attributes

AttributeDescription
requiredField must not be empty
minlengthMinimum number of characters
maxlengthMaximum number of characters
min / maxMin/max value for numbers and dates
patternRegex pattern the value must match
type="email"Validates email format automatically

Add novalidate to the form tag to disable browser validation (useful when using JS validation).

Example
<form action="/register" method="post">
  <input type="text"
    name="username"
    placeholder="Username"
    required
    minlength="3"
    maxlength="20">

  <input type="email"
    name="email"
    placeholder="Email"
    required>

  <input type="password"
    name="password"
    placeholder="Password (min 8 chars)"
    required
    minlength="8">

  <input type="number"
    name="age"
    placeholder="Age"
    min="18"
    max="120">

  <button type="submit">Register</button>
</form>