Menu
Forms & Inputs

HTML Form Validation

required, pattern, min/max, minlength/maxlength.

1Validation Without JS

Browsers can validate inputs before submission using attributes. Add required, pattern, min, max, minlength, maxlength, and the browser shows a built-in error.

Example Code
<form>
  <input
    name="username"
    required
    minlength="3"
    maxlength="20"
    pattern="[A-Za-z0-9_]+"
    title="Letters, numbers, underscore"
  />
  <input type="email" required />
  <input type="number" min="18" max="120" required />
  <button>Submit</button>
</form>

Finished reading?

Mark this topic as complete to track progress.