Skip to content

DigitalA11Y

Your Accessibility Partner

  • Home
  • ServicesExpand
    • WCAG Audit Services
    • VPAT/ACR Services
    • Accessibility Consulting
    • PDF Remediation
    • Accessibility Trainings
    • Website Remediation
    • Design Audit
  • Free ToolsExpand
    • Accessibility Checker
    • A11Y Cost Calculator
    • A11Y Bookmarklets
    • Color Contrast Extension
    • WCAG Contrast Checker
  • ResourcesExpand
    • A11Y Articles
    • WCAG Primer
    • ARIA Cheatsheet
    • A11Y Tools
    • A11Y Patterns
    • A11Y Cheatsheets
  • Contact
Search
DigitalA11Y
Your Accessibility Partner
Search

HTML 5 Client-side Validations

HTML 5 client-side validations are a very useful feature: they allow rudimentary validation of user data without submitting anything to the server. They are supported to a high degree by modern browsers and screen readers. Still, you should obviously never think of them as a complete replacement for server-side data validation.

HTML 5 client-side validations have a lot of benefits, for example:

  • They make resolving validation errors faster and more understandable, thus resulting in a better user experience.
  • As such, they can also reduce network and server load.

Validations can be added in two ways:

  1. Implicitly by setting the type of an input to a value that comes with some validations by itself, for example type="email".
  2. Explicitly by adding validations manually through the respective attributes, for example required or pattern.

The following example demonstrates a few of those validations:

  • All inputs are required (using required attribute).
  • The “Email” input checks for a valid input format (using type="email" attribute).
  • The “Password” input checks for a custom pattern (using pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" attribute).
    • This requires an input of at least six characters with at least one number, one lowercase, and one uppercase letter.
    • To make the pattern available to the user in a human-readable form, you can use the title attribute like this:  title="Minimum 6 characters containing lowercase, uppercase, and

Working Example

Gender

Explanation

All browsers handle these validations to their liking. In general, they work quite similarly: when the user submits the form, the browser sets the focus automatically to the first invalid input. The validation error is then announced by the screen reader.

A few notes though:

  • Some screen readers announce missing required values automatically as “invalid”, while others do not.
  • Some screen readers announce both an input’s name and validation error, while others only announce the validation error.
    • The latter case is a minor inconvenience, as the user may have to find out the input’s name manually (which is easy, but still an annoyance).

Code

  • HTML
  • CSS
  • JavaScript
<form>
  <div class="control">
    <label for="name">Full name</label><input id="name" required="" type="text" />
  </div>
  <div class="control">
    <label for="email">Email</label><input id="email" required="" type="email" />
  </div>
  <div class="control">
    <label for="password">Password</label><input id="password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" required="" title="Minimum 6 characters containing lowercase, uppercase, and at least one number" type="password" />
  </div>
  <fieldset>
    <legend>Gender</legend>
    <div class="control">
      <input id="gender_male" name="gender" required="" type="radio" value="male" /><label for="gender_male">Male</label>
    </div>
    <div class="control">
      <input id="gender_female" name="gender" type="radio" value="female" /><label for="gender_female">Female</label>
    </div>
  </fieldset>
  <div class="control">
    <input id="accept_agbs" required="" type="checkbox" /><label for="accept_agbs">I accept the terms and conditions</label>
  </div>
  <div class="control">
    <input type="submit" value="Register" />
  </div>
</form>

.control, fieldset {
margin: 6px 0;
}

label {
display: inline-block;
width: 120px;
vertical-align: top;
}

input + label {
width: auto;
}

.error {
color: red;
margin-top: 0;
margin-left: 120px;
}

label + .error {
margin-left: 0;
}

fieldset .error {
margin-left: 0;
}

NIL

Company

  • About
  • Blog
  • Careers
  • Contact

Services

  • Accessibility Audits
  • Accessibility Consulting
  • VPAT/ACR
  • Accessibility Trainings

Compliance

  • WCAG
  • ADA
  • Section 508
  • EN 301 549
  • EAA
  • AODA Compliance Services — Make Your Digital Assets Accessible in Ontario
  • ACA

Resources

  • Accessibility Resources
  • Understanding WCAG
  • WCAG Checklist
  • Understanding WAI-ARIA

Legal

  • Privacy Policy
  • Terms and Conditions
  • Disclaimer
  • Accessibility Statement for digitala11y.com
  • Sitemap

© 2025 DigitalA11Y
All Rights Reserved

Linkedin Twitter Facebook Instagram YouTube

DigitalA11Y
Plot No 108, 3rd Cross Rd, Saipuri Colony,
Hastinapuri Colony, Sainikpuri, Secunderabad -500094
Telangana, India.

Tel:(+91)99082 66680,
E-mail: [email protected]

Scroll to top
  • Home
  • Services
    • WCAG Audit Services
    • VPAT/ACR Services
    • Accessibility Consulting
    • PDF Remediation
    • Accessibility Trainings
    • Website Remediation
    • Design Audit
  • Free Tools
    • Accessibility Checker
    • A11Y Cost Calculator
    • A11Y Bookmarklets
    • Color Contrast Extension
    • WCAG Contrast Checker
  • Resources
    • A11Y Articles
    • WCAG Primer
    • ARIA Cheatsheet
    • A11Y Tools
    • A11Y Patterns
    • A11Y Cheatsheets
  • Contact