跳到正文
Skillpedia
网站与界面(前端)75k · #2858

form-labels

它能做什么

这项技能检查表单输入框是否有清晰且相连的标签。适用于构建许多人需要填写的表单的开发者。

适用场景

  • ✓当表单字段只有占位文字,没有真正的标签的时候。
  • ✓当一组复选框或单选按钮没有共同的问题说明的时候。
  • ✓当用户无法点击标签来聚焦其输入框的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/form-labels/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/form-labels/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请检查我表单中的每个字段是否都有正确的标签。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会使用 for 和 id 属性验证每个输入框是否有相连的标签。它会用可见的标签替换只有占位文字的字段,并使用带有 legend 的 fieldset 包裹相关选项。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Associate labels with form controls

Properly associated labels ensure that screen readers can identify the purpose of form inputs and increase the clickable area for users with motor impairments.

Quick Reference

  • Use <label> elements for all form inputs
  • Connect labels using for and id attributes
  • Placeholder text is not a label and must not be the only field name
  • Use <fieldset> and <legend> when multiple controls share one question
  • Ensure every input has a clear, accessible name

Check

Verify that all form controls (input, select, textarea) have programmatically associated labels using the 'for' and 'id' attributes. Flag placeholder-only labels and grouped controls that lack a fieldset legend.

Fix

Add a <label> element with a 'for' attribute that matches the 'id' of the corresponding input field. Replace placeholder-only labels with real label text and wrap related checkboxes or radio buttons in a <fieldset> with a <legend>.

Explain

Explain why associated labels are critical for screen reader users and how they improve the hit area for touch and mouse users.

Code Review

Review the rendered markup and interactive states that affect Associate labels with form controls. Flag exact elements, roles, labels, focus behavior, or keyboard interactions that violate the rule, and note how to verify the fix with browser accessibility tooling or assistive tech. Specifically check for placeholder-only labels and question groups that visually share a heading but lack a semantic <fieldset> and <legend>.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/accessibility/form-labels

常见问题

为什么占位文字不够?

占位文字会在用户开始输入时消失,这项技能指出它不能作为标签。

fieldset 有什么作用?

它将相关控件(例如单选按钮)归入一个共同的问题之下,这个问题称为 legend。

标签为什么对触屏用户有帮助?

相连的标签会增加可点击区域,这对有运动障碍的人有帮助。

详情

作者的原始描述

Use when reviewing rendered HTML, interactive components, or design-system patterns related to Associate labels with form controls. Check native semantics first, then inspect keyboard behavior, focus flow, accessible names, and screen-reader output where relevant.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2858
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能