Is there a standardized method for accessibility and form semantics?

With so many articles on "correct", "semantic" and "accessible" use of forms and architecture, I am rethinking how I approach forms. There are literally so many variations on what is "correct" that I am not 100% more than accurate.

In an MDN article ( here ), he mentions:

In this example, the screen reader says "Small fruit juice size" for the first widget, "Medium fruit juice size" for the second, and "Fruit juice size large" for the third.

<form>
  <fieldset>
    <legend>Fruit juice size</legend>
    <p>
      <input type="radio" name="size" id="size_1" value="small" />
      <label for="size_1">Small</label>
    </p>
    <p>
      <input type="radio" name="size" id="size_2" value="medium" />
      <label for="size_2">Medium</label>
    </p>
    <p>
      <input type="radio" name="size" id="size_3" value="large" />
      <label for="size_3">Large</label>
    </p>
  </fieldset>
</form>

      

Now I can see the benefit of this for something like the above example, however, let's say I made a multi-step shopping cart, I would not want the assistive technologies to say "Checkout: cc-number", "Checkout: cc-date" using "checkout" in front of each label. Especially in cases where steps are indicated. This would be repetitive and sometimes confusing, I would guess ... But I have always grouped form sections within <fieldset>

. Now I am rethinking with fieldset

and legend

in general, but is it going against semantics now? What is the compromise? Is there a balance?

Also, and I will use the same MDN article so that I don't send you all over the internet,

Note that even disregarding assistive technology, having a formal set of labels for a given widget allows users to click on a shortcut to activate the corresponding widget in all browsers. This is especially useful for radio buttons and check boxes.

Some assistive technologies may have problems handling multiple shortcuts for a single widget. Because of this, you must insert a widget inside its corresponding element to create an accessible form.

<form>
  <p>
    <input type="checkbox" id="taste_1" name="taste_cherry" value="1">
    <label for="taste_1">I like cherry</label>
  </p>
  <p>
    <label for="taste_2">
      <input type="checkbox" id="taste_2" name="taste_banana" value="1">
      I like banana
    </label>
  </p>
</form>

      

Now in this case, labeling for both of these elements is fairly common, I've used both methods, but is there a balance between accessibility and semantics here? I tend to put the label without wrapping the input for code consistency, and I know their strong discussion on this (basically the ability to opt out for

and not need id

and / or have labels in different areas of the markup). So, I'm not trying to rephrase the debate here, I tend to use for

and id

, regardless of whether I wrap the elements in label

or not. But if there is an accessibility issue for one, then why is the latter not the gold standard?

One more point, WAI-Aria rules are now contributing, so how much do these rules really affect the accessibility and semantics of the form?

<p>Required fields are followed by <strong><abbr title="required">*</abbr></strong>.</p>
<form>
  <fieldset>
    <legend>Fruit juice size*</legend>
    <p>
      <label for="size_1">
        <input type="radio" name="size" id="size_1" value="small" aria-labelledby="size_1_label" />
        <span id="size_1_label" required aria-required="true">Small</span>
      </label>
    </p>
    <p>
      <label for="size_2">
        <input type="radio" name="size" id="size_2" value="medium" aria-labelledby="size_2_label" />
        <span id="size_2_label">Medium</span>
      </label>
    </p>
    <p>
      <label for="size_3">
        <input type="radio" name="size" id="size_3" value="large" aria-labelledby="size_3_label" />
        <span id="size_3_label">Large</span>
      </label>
    </p>
  </fieldset>
</form>

      

I'm really just wondering if there is a standardized way to approach when dealing with semantic and accessible markup. So far, it seems like people are just doing what they think is right and then vocalizing their thoughts all over the internet.

I have read the W3C drafts and guidelines, but even they use different examples. Does anyone have any evidence of an approach that actually improves accessibility and semantics with respect to forms? Are there any specific websites that have time to check this out and come up with an accurate conclusion that I could consider?

+3


source to share


1 answer


The answer to your question is actually "it depends".

All available inscriptions above are valid. So if you're just looking for accessible markup, you can use any of the examples. The rest of the decisions really boil down to

  • error handling and
  • additional instructions

Error processing

When errors appear on your form, they should be programmatically linked to the form fields they reference. This can be done in two ways:

Add an error to the label

You can add error text to the label itself. Having a wrapped label gives you a lot of flexibility as to the order in which that error text appears in the DOM. you can put an error before label after label after input or before input. For this reason, you can use the wrap technique instead of the no wrap technique:

<label>My Input
    <input type="text" aria-invalid="true" id="myinput" name="myinput"/>
    <span class="error">The input field must be a valid username</span>
</label>

      



Link error with ARIA

The second way is to bind the error using ARIA. This is very flexible as it allows multiple elements to form an input label and can also be used for additional instructions.

<label id="mylabel">My Input</label>
<input type="text" aria-invalid="true" aria-labelledby="mylabel myerror"/>
<span id="myerror" class="error">The input field must be a valid username</span>

      

Now, if your input is a checkbox or radio button, you need to maintain associations for

and id

so that the user can click (or touch) the shortcut to activate the checkbox / radio.

Additional instructions

As mentioned above, using ARIA labeling techniques, you can associate multiple elements with a single input field. This is useful for providing additional instructions and hints. aria-labelledby

is used for an accessible name (label), whereas it aria-describedby

can be used for a hint and can also refer to multiple elements with multiple identifiers.

<label id="mylabel">My Input</label>
<input type="text" aria-invalid="true" aria-labelledby="mylabel myerror" aria-describedby="unameinstructions"/>
<span id="myerror" class="error">The input field must be a valid username</span>
<span id="unameinstructions">A valid user name must contain at least one alpha, one numeric character and must be at least 8 characters</span>

      

Here is a presentation I created for the available dynamic forms http://www.slideshare.net/dylanbarrell/accessible-dynamic-forms-27169766 , it links to the example code which can be found here https://github.com/dylanb/ a11yvalid and the provided best practices example (except perhaps the CSS style selection) can be found here http://dylanb.github.io/bower_components/a11yfy/examples/form-validation.html

+5


source







All Articles