跳到正文
Skillpedia
界面(UI/UX)75k · #2852

focus-styles

它能做什么

这项技能检查网站在键盘用户于各个控件之间移动时,是否显示可见的轮廓。适用于希望样式具备无障碍性的开发者和设计师。

适用场景

  • ✓当你的 CSS 去掉了按钮或链接的默认轮廓的时候。
  • ✓当键盘用户看不到当前选中的是哪个控件的时候。
  • ✓当你设计自定义按钮或链接样式的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能