Code Snippets
/

Accessible Semantic Form Markup

Accessible Semantic Form Markup

A login or signup form is the highest-traffic interaction on most apps, and getting the semantic markup right pays dividends in screen-reader support, autofill quality, and form validation. This snippet covers a labelled email-and-password form, a form-with-error-summary using `aria-describedby`, and a multi-step fieldset pattern for grouped inputs.

HTML
Medium
3 snippets
html-elements
html-forms
accessibility
code-template

600 views

6

<form action="/login" method="post">
    <div>
        <label for="email">Email</label>
        <input
            id="email"
            name="email"
            type="email"
            autocomplete="email"
            required
        >
    </div>
    <div>
        <label for="password">Password</label>
        <input
            id="password"
            name="password"
            type="password"
            autocomplete="current-password"
            minlength="8"
            required
        >
    </div>
    <button type="submit">Sign in</button>
</form>

Every input needs a <label for="id"> (not just placeholder text) so screen readers announce the field name and clicking the label focuses the input. autocomplete="email" and autocomplete="current-password" give the browser and password manager the right hints, which is what triggers autofill and one-tap login. The type="email" activates email-style mobile keyboards and basic format validation; minlength="8" adds a server-side-friendly client check. These tiny attributes make the difference between a clunky and a polished login.