Web Historical Disclaimer:

This is a historical page and is no longer maintained. Read our Web history statement for more information.

Skip to Main ContentThe University of Texas at Austin
Accessibility Institute
Making the Web more usable for everyone
 

Home

Consulting

Resources

Research

About Us

Site Map

How-Tos and Demos

Accessible Forms

Example: Radio buttons with <fieldset>, <legend>, and <label>

Project Information
Site size


This example uses the <fieldset>, <legend>, and <label> elements in addition to the radio buttons themselves (<input> elements of type="radio"). This combination is especially important if you use a <table> to control the position of the radio buttons and the text beside them. The <fieldset> element contains the group of related items—in this case, the items about the size of the project. The <legend> element contains the prompt. The <label> elements connect the text on the screen with the appropriate radio buttons. This makes it possible for screen readers to identify all the components of the form and report them correctly to the user.

 

How to do it

Code example for radio buttons with <fieldset> and <legend> Opens a new window

 

Rationale

Many Web developers use tables to lay out their forms. This can pose serious problems if the <input> elements aren't labeled correctly, and it's especially problematic where radio buttons are concerned. If the prompt for a group of radio buttons is in one table element and the radio buttons themselves are in another element in the same table, screen readers can't identify the prompt-- even if the individual radio buttons are correctly associated with their labels.

To solve this problem, we used a <fieldset> element to group the radio buttons, then used the <legend> element (part of the fieldset) to display the prompt; each radio button has its own <label> element. We then put the entire <fieldset> inside a single data cell (<td> element). JAWS reported the radio buttons correctly-- that is, each one is associated both with its label and with the legend

 

How it sounds with the JAWS screen reader

Listen to JAWS reading this form Opens a new window

 

JAWS transcript

[Site size less than fifteen pages radio button checked.
Site size more than fifteen pages radio button checked. (User presses DOWN ARROW)
Tab. Submit query button.
Tab reset button.]

 

Applicable Accessibility Standards and Guidelines

 
Last Modified: 2008 September 28