npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

a11y-validate

v1.0.0

Published

Accessible form validation — error summary, focus management, and aria-describedby wiring, on top of native HTML5 validation. Zero dependencies.

Readme

a11y-validate

Accessible form validation. Zero dependencies, one file, works with any framework or plain HTML.

The problem

Most form-validation libraries show a red message under a field and call it done. A screen reader user gets none of that: nothing announces that submission failed, nothing tells them how many fields have problems, focus doesn't move anywhere useful, and the error text is often not actually linked to the field it describes. The visual experience and the accessible experience quietly diverge.

a11y-validate builds on the pattern GOV.UK and the US Web Design System converged on after real user testing: a focus-managed error summary at the top of the form, linked to each problem field, plus proper aria-invalid / aria-describedby wiring on every field itself.

Install

Drop the file in and include it — no build step, no bundler required:

<script src="a11y-validate.js"></script>

Or via npm if you're bundling:

npm install a11y-validate

Quick start (zero JS config)

Add data-a11y-validate to any form. Standard HTML5 validation attributes (required, pattern, minlength, type="email", etc.) are picked up automatically — a11y-validate uses the browser's own Constraint Validation API rather than reimplementing it.

<form data-a11y-validate>
  <label for="email">Email address</label>
  <input type="email" id="email" name="email" required
         data-error-required="Please enter your email address."
         data-error-type="Please enter a valid email address.">

  <button type="submit">Submit</button>
</form>
<script src="a11y-validate.js"></script>

Submit it empty or with something invalid and you'll see:

  • An error summary box appears at the top, focus moves to it, and a screen reader announces it immediately
  • Each summary entry links directly to its field
  • The field itself gets aria-invalid="true" and an error message wired via aria-describedby, so a screen reader announces the specific problem the moment that field is focused

Custom messages per validation type

Any HTML5 validation failure can have a custom message via a data-error-* attribute:

| Attribute | Fires when | |---|---| | data-error-required | field is empty but required | | data-error-type | type="email"/type="url"/etc. doesn't match | | data-error-pattern | pattern attribute doesn't match | | data-error-minlength / data-error-maxlength | minlength / maxlength violated | | data-error-min / data-error-max | min / max violated | | data-error-step | step violated |

If you don't provide one, a sensible default is used.

Custom validation rules

For anything HTML5 attributes can't express (password strength, matching another field, an async-feeling check), use programmatic init instead of the data-a11y-validate attribute:

A11yValidate.init(document.getElementById('signup-form'), {
  rules: {
    password: (value) => value.length >= 8 ? null : 'Password must be at least 8 characters.'
  },
  onValidSubmit: (event, values) => {
    // values = { username: '...', password: '...' }
    // handle your fetch/submit here — event.preventDefault() is already called
  }
});

A rule function receives the field's current value and returns an error string, or null/falsy when valid. Rules run after built-in HTML5 validation, so a required field with an empty value never reaches your custom rule.

If onValidSubmit isn't provided, a successful validation lets the form submit natively (a real POST navigation).

Behavior details worth knowing

  • Errors don't appear while first filling in the form. Live revalidation on blur/input only activates after the user has attempted a submit once — so tabbing through an untouched form doesn't trigger a wall of red text.
  • Fields don't need a pre-set id. One is generated automatically if missing, so error linking always works.
  • The error summary is focused, not the first field. This matches the tested GOV.UK/USWDS pattern — screen reader users hear the full picture ("N problems, here's what they are") before moving to fix anything, rather than landing on field one with no context.

Styling

Minimal inline styles are applied by default (red border/text for errors) so it's usable out of the box. Override with your own CSS by targeting .a11y-error, .a11y-error-summary, .a11y-error-summary-heading, and .a11y-error-summary-list.

Why this exists

Most "accessible" form libraries are accessible in name only — a color change on invalid fields, no summary, no focus management, no verified aria-describedby linkage. This one leans entirely on the browser's own validation engine for the "what's invalid" question, and spends its actual code on the accessibility wiring most libraries skip.

Built by Cybergeon Technologies.

License

MIT © Cybergeon Technologies — see LICENSE.