You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为表单控件组设置Label For属性以满足508合规要求?

处理单选按钮组的508合规标签问题

Great question! When working on 508 compliance for radio button (or checkbox) groups, you’ve already nailed the individual option labels (each <label for="..."> tied to a single radio button ID—perfect). For group-level descriptions like "Speed Assessment", the native, most accessible solution is to use the <fieldset> and <legend> elements—this is the standard WCAG/508-recommended approach.

Why <fieldset> + <legend>?

  • <fieldset> wraps all related form controls to semantically group them together, so assistive tech recognizes they’re part of the same set.
  • <legend> acts as the "label" for the entire group. Screen readers will announce the legend text when users navigate into the group, giving them clear context for the options they’re choosing.

Modified Example Code

Here’s how to update your HTML to fix the "Speed Assessment" group:

CSS (unchanged):

input[type=radio] { float: left; }

Updated HTML:

<form id="myForm">
  <label for="distance">Distance:</label>
  <input type="text" id="distance"/>

  <label for="unit">Unit:</label>
  <select id="unit">
    <option value="miles">Miles</option>
    <option value="km">Km</option>
  </select>

  <!-- Replace the <p> with fieldset + legend -->
  <fieldset>
    <legend>Speed Assessment:</legend>
    <label for="speedSlow">Slow</label>
    <input type="radio" name="speed" id="speedSlow"/><br/>
    <label for="speedMedium">Medium</label>
    <input type="radio" name="speed" id="speedMedium"/><br/>
    <label for="speedFast">Fast</label>
    <input type="radio" name="speed" id="speedFast"/><br/>
  </fieldset>
</form>

Key Notes:

  • You don’t need a for attribute on <legend>—it’s inherently linked to the <fieldset> and its contents.
  • This method works reliably across all screen readers and browsers, making it more dependable than ARIA-only workarounds (though aria-labelledby can be used in edge cases, <fieldset>/<legend> is always preferred for native semantic support).
  • Your existing labels for the text input and dropdown are already fully compliant—no tweaks needed there!

内容的提问来源于stack exchange,提问作者gene b.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:57:13