Labels or instructions are provided when content requires user input.
Testing & RemediationHow to test: Open your website in your browser of choice and examine each page for the presence of content that requires user input. For each input, does it have an appropriate label? For inputs that have restrictions/requirements, are there instructions provided for the user? How to remediate: All content that requires user input must have an appropriate label or instructions for the user. There are a number of ways to accomplish this:
- Provide instructions at the beginning of the form
- Use the aria-describedby property to provide a descriptive label
- Use aria-labelledby to concatenate a label from several text nodes
- Position labels to maximize predictability of relationships
- Indicate required form controls using labels or a legend
- Use label elements to associate text labels with form controls
Questions and Answers
Legend is a broad label used for a group of objects. Label is used for labeling specific elements.
Your site should have the correct semantic elements (header, main, footer, article, etc) in the order that they are intended to be read. This means that sometimes this isn't the order that makes styling the page the easiest. You must also ensure that all your heading levels are hit in the order. This means that you should not skip from an h1 to an h4, and so on.
There are many form specific elements that can be used to describe what's going on. As you've already mentioned, each input requires that it has a corresponding label. If you would like to further organize and give meaning to your form, you can use the 'fieldset' element to group related inputs. Within each fieldset, you can create a 'legend' that describes the inputs. For instance, let's say we have a form that asks a user for their personal information, and details about an order. The source code could look something like this.
<form> <fieldset> <legend>Enter Your Information</legend> <label for="first">First Name</label> <input type="text" name="first"> <!-- etc --> </fieldset> <fieldset> <legend>Order Details</legend> <label for="size">Size</label> <select name="size"> <!-- sizes --> </select> <!-- etc. --> </fieldset> </form>
This warning refers to form labels that exist in the web pages markup but is not appropriately associated with a corresponding field. Best practice dictates that within a form every input element has a matching label element, this can be done by attributing the for field of the label with the same element id of the desired input.
How to resolve this:Consider the following markup, this code passes accessibility scanners:
<form> <label for="name">Your Name:</label> <input id="name" type="text" placeholder="Enter your Name"> <input type="submit" value="Submit"> </form> Note:
- The text-input field has the id parameter "name"
- The label field associated with the text field has the for parameter "name"
This question depends on a number of factors including size of site, desired level of conformance, your developer's understanding of accessibility techniques, etc. Accessible Web is here to help. Reach out and we can discuss your site specifically.