Follow these requirements to code forms on websites outside of the Energy.gov Drupal environment. If you want to code a webform on Energy.gov, see Energy.gov Webforms.

Labels

To meet Section 508 requirements, all form fields must have text labels associated with them using appropriate markup For example, a field may be coded explicitly using the id and for attributes like this:

<label for="firstname">First name:</label>
<input type="text" name="firstname" id="firstname">

To hide label text, such as on a search bar, you can use the aria-label attribute.

<input type="text" name="search" aria-label="Search">
<button type="submit">Search</button>

See more methods of labeling elements on the Web Accessibility Initiative’s label tutorial.

Grouping Controls

Grouping related form elements helps all users and can be done both visually and in the code. Use the <fieldset> element as a container for related form controls and the <legend> element to describe the group. For example:

<fieldset>
<legend>I want to subscribe to:</legend>
    <input type="radio" name="subscribe" id="newsletter" value="newsletter">
    <label for="newsletter">Monthly Newsletter</label>

    <input type="radio" name="subscribe" id="updates" value="updates">
    <label for="updates">Weekly Updates</label>
</fieldset>

Instructions

Provide instructions to help users complete the form. Indicate required fields, data formats, and any other relevant information.

Instructions should not rely solely on sensory characteristics such as color, shape, size, visual location, orientation, or sound.

Keyboard Accessibility

Forms should be able to be completed using only a keyboard.

Errors

Notify the user if the form submission was successful or if there are errors. Errors should be easy to understand and have simple instructions for how they can be resolved.

CAPTCHAs

Using CAPTCHAs should be avoided because they are inaccessible to many groups of users. 

Time Limits

Whenever possible, forms should not be given a time limit. Users should be allowed to complete a form at their own pace.

If a timed response is required for security reasons, the user should be alerted and given sufficient time to indicate more time is required.

For more information, see WebAim's article on creating accessible forms.