SynfraCore
Synfracore
Start Learning
Navigation

Academies

Platform

RoadmapsLabsCertificationsInterviewPYQsAI AssistantCareer
Start Learning Free Learning Roadmaps

HTML & Semantic MarkupIntermediate

Real-world patterns, best practices, and deeper topics

📄
Last updated Sep 2026
Expert Content

HTML — Intermediate

Form validation, beyond `required`

The browser does real validation work for free if you use the right input types and attributes — reimplementing this in JavaScript is both extra work and easy to get subtly wrong (a regex email check that rejects a valid address is a classic self-inflicted bug).

html
<form>
  <label for="username">Username</label>
  <input type="text" id="username" name="username"
         minlength="3" maxlength="20" pattern="[a-zA-Z0-9_]+"
         title="Letters, numbers, and underscores only, 3-20 characters" required>

  <label for="age">Age</label>
  <input type="number" id="age" name="age" min="13" max="120" required>

  <label for="website">Website</label>
  <input type="url" id="website" name="website" placeholder="https://example.com">

  <button type="submit">Submit</button>
</form>
html
<!-- CSS pseudo-classes react directly to HTML5 validation state -->
<style>
  input:invalid { border-color: red; }
  input:valid { border-color: green; }
  input:required:invalid { background: #fff0f0; }
</style>

The flow, end to end: the browser blocks submission and shows a native validation message on an invalid field, before your form's submit handler (if any) even runs — this is why relying purely on JavaScript validation for a basic "is this field empty" check duplicates work the browser already does natively, correctly, and accessibly.

User submits form
Browser checks constraints
required, pattern, min/max, type
Invalid: native message shown, submit blocked
Valid: form actually submits

Accessible custom widgets — ARIA as a deliberate fallback

Native elements should always be the first choice — a real

Share:
Join our Community
Daily tips, job alerts, interview help — join engineers learning together
Up Next
🚀
HTML & Semantic MarkupAdvanced
Production patterns, performance, security hardening
Also Worth Exploring
← Back to all HTML & Semantic Markup modules
FundamentalsAdvanced