foundation

Native controls and validation

Use input types, constraints, required fields, pattern, validity states, and progressive enhancement.

Native form controls provide keyboard behavior, mobile keyboards, validation states, submission semantics, and accessibility hooks. Input types, `required`, `min`/`max`, `pattern`, `disabled`, `readonly`, `fieldset`, and the Constraint Validation API should be the baseline before custom JavaScript.

					<form>
  <label>Email <input name="email" type="email" required></label>
  <button type="submit">Save</button>
  <button type="button">Cancel</button>
</form>
				

Button `type` matters: submit triggers form submission; button does not. Always set it explicitly.

On interviews: why `email`, `number`, `date`, radio groups, and button types matter.

Common pitfalls: div controls lose keyboard behavior; client validation is UX, not security — servers must validate again.

The trade-off is polished custom widgets versus native speed, accessibility, and mobile keyboards — enhance natives before replacing them.

Checklist:

  • Choose specific input types.
  • Set explicit button types.
  • Use built-in constraint validation.
  • Re-validate on the server.