Skip to main content
Albero Academy

Form Validation

Built-in HTML validation attributes.

Forms8 min

HTML provides built-in validation through attributes — the browser checks input before the form submits, with no JavaScript needed for the basics.

Validation attributes

constraints
<input type="text" required minlength="2" maxlength="50" />
<input type="email" required /> <!-- must be a valid email -->
<input type="number" min="0" max="100" step="5" />
<input type="text" pattern="[0-9]{6}" title="6 digits" /> <!-- regex -->

Client + server

Key takeaways

  1. 01HTML attributes give built-in validation: required, minlength/maxlength, min/max, pattern.
  2. 02The browser checks these before submit, with no JavaScript needed.
  3. 03pattern uses a regex; type="email"/"url" validate formats.
  4. 04Never trust client validation alone — always re-validate on the server.

Finished this chapter?

Mark it complete to track your progress through HTML.