DEV Community

Cover image for How to Build Accessible HTML Forms (And the Tools That Help)
kandz
kandz

Posted on Originally published at tools.kandz.me

How to Build Accessible HTML Forms (And the Tools That Help)

Building HTML forms by hand is tedious.

You forget a name attribute. You miss a for on a label. Accessibility breaks. Validation fails silently.

Whether you're building a simple contact form or a complex multi-step Typeform-style experience, the foundation is always the same: solid, semantic HTML.

Let's look at what makes a form accessible and how to build one without losing your mind.


The Accessibility Problem

Forms are the most common point of failure for web accessibility. If a screen reader can't understand your form, the user can't complete it.

The most common mistakes:

  • Missing Labels: Using placeholders instead of <label> elements.
  • Broken Associations: Having a label, but forgetting the for attribute to link it to the input's id.
  • Missing Names: Forgetting the name attribute, which means the data never gets submitted.
  • Silent Errors: Not using aria-live regions or aria-invalid to announce validation errors to screen readers.

The Manual Way (The Foundation)

A perfect, accessible input looks like this:

<div class="form-group">
  <label for="email">Email Address</label>
  <input 
    type="email" 
    id="email" 
    name="email" 
    required 
    aria-required="true"
    autocomplete="email"
  />
</div>
Enter fullscreen mode Exit fullscreen mode

You need:

  1. The for attribute on the label matching the id on the input.
  2. The name attribute for form submission.
  3. The correct type (e.g., email, tel, password).
  4. The required attribute for native validation.
  5. autocomplete for better user experience.

Writing this for 20 fields takes time. Writing it for a complex form with checkboxes, radio groups, and select dropdowns takes even longer.


The Step-by-Step Form Problem

If you want a Typeform-style experience, you add JavaScript and CSS to the mix.

You need to:

  • Hide all steps except the current one.
  • Animate the transition between steps.
  • Validate the current step before allowing the user to proceed.
  • Manage focus (move focus to the first input of the new step).
  • Announce the step change to screen readers using aria-live.

This is complex. If the underlying HTML isn't perfect, the JavaScript will break.


The Visual Way

If you want to build the accessible HTML foundation without writing every tag by hand, I built a free HTML Form Code Builder.

What it does:

  • Visually designs HTML5 forms
  • Adds validation attributes automatically
  • Generates accessible, semantic markup

Why it's useful:

  • No installation
  • No upload (100% client-side)
  • Ensures you don't miss for, id, or name attributes
  • Fast

Try It

HTML Form Code Builder

100% client-side. Nothing uploaded.


What's your biggest frustration with building forms? Let me know in the comments.

Top comments (0)