focus-styles
它能做什么
这项技能检查网站在键盘用户于各个控件之间移动时,是否显示可见的轮廓。适用于希望样式具备无障碍性的开发者和设计师。
适用场景
- ✓当你的 CSS 去掉了按钮或链接的默认轮廓的时候。
- ✓当键盘用户看不到当前选中的是哪个控件的时候。
- ✓当你设计自定义按钮或链接样式的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/focus-styles/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请确保我用键盘操作时,按钮会显示可见的轮廓。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会在样式表中查找被移除的轮廓,并检查是否有可见的替代样式。它会建议使用具有足够对比度和清晰偏移量的 focus-visible 样式。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Provide visible custom focus indicators
Users who navigate by keyboard (people with motor disabilities, power users, people in assistive technology contexts) rely entirely on focus indicators to know where they are on the page. Removing outlines without replacement makes an entire site unusable for keyboard users. WCAG 2.4.7 requires a visible focus indicator, and WCAG 2.4.13 defines a stronger size-and-contrast target for custom indicators.
Quick Reference
- Never use outline: none or outline: 0 without a visible :focus-visible replacement
- Use :focus-visible instead of :focus to show indicators only during keyboard navigation
- Focus indicators must have 3:1 contrast ratio against adjacent colors (WCAG 2.2)
- Provide at least 2px solid outline with an offset for a high-quality focus ring
- If a focus ring is drawn with pseudo-elements, verify it is anchored to the correct positioned element and not clipped by
overflow: hidden - If the component uses a stretched-link pattern, verify the visible focus ring follows the actual interactive element rather than a parent wrapper by accident
Check
Find all instances of outline: none, outline: 0, or :focus { outline: none } in this CSS. Check if they provide an alternative visible focus indicator. If the replacement uses pseudo-elements, also verify the ring cannot be clipped or misplaced by overflow or missing positioning context.
Fix
Replace outline: none on :focus with :focus-visible styles that provide a clearly visible custom focus ring with appropriate contrast.
Explain
Explain the difference between :focus and :focus-visible, why focus styles matter for accessibility, and how to design an accessible focus ring.
Code Review
Review stylesheets, component styles, and responsive states related to Provide visible custom focus indicators. Flag exact selectors, declarations, or breakpoints that violate the rule in the rendered UI.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/css/focus-styles
常见问题
为什么不直接去掉轮廓?
键盘用户依靠轮廓知道自己所在的位置,去掉它会使网站难以使用。
什么是 focus-visible?
它是一个 CSS 选择器,主要在键盘导航时显示焦点样式,而不是在鼠标点击后显示。
需要什么对比度?
这项技能提到,焦点指示器与相邻颜色之间应有 3 比 1 的对比度。
详情
作者的原始描述
Use when reviewing stylesheets, component styles, and responsive behavior related to Provide visible custom focus indicators. Check the rendered layout across breakpoints and interaction states before proposing a fix.
热度
- GitHub 星标
- 75k
- 排名
- #2852
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。