dark-mode-css
它能做什么
这项技能为网站的颜色添加深色版本。适合希望网站在夜间看起来舒适,并尊重设备设置的开发者。
适用场景
- ✓当访客要求用深色主题在夜间阅读时。
- ✓当网站的固定颜色在深色背景上显示不正常时。
- ✓当你希望网站跟随每位访客设备的浅色或深色设置时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/dark-mode-css/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能为我的网站添加跟随系统设置的深色模式吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会把颜色移入具名的值中,并为深色模式设置不同的值。它还可以添加一个切换开关,让访客自行选择主题。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Support dark mode with prefers-color-scheme
More than half of users prefer dark mode for reduced eye strain, especially in low-light environments. Users with photosensitivity rely on it. Implementing dark mode via prefers-color-scheme respects the user's OS preference without them needing to find a toggle, and CSS custom properties make it a clean, maintainable addition rather than a disruptive refactor.
Quick Reference
- Use @media (prefers-color-scheme: dark) to apply dark mode styles
- Define light/dark colors as CSS custom properties on :root for easy switching
- Support a manual toggle by storing preference in localStorage and setting a data-theme attribute
- Ensure dark mode colors maintain WCAG contrast ratios
Check
Check if this CSS supports dark mode. Look for prefers-color-scheme usage or a data-theme attribute pattern. Identify any hard-coded colors that would look wrong in dark mode.
Fix
Implement dark mode by extracting colors to CSS custom properties and redefining them inside a prefers-color-scheme: dark media query.
Explain
Explain how to implement dark mode with CSS custom properties, the prefers-color-scheme media query, and a JavaScript toggle for user preference.
Code Review
Review stylesheets, component styles, and responsive states related to Support dark mode with prefers-color-scheme. 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/dark-mode-css
常见问题
网站怎么知道访客想要深色模式?
浏览器会报告设备设置,页面据此自动选择深色配色。
访客可以自己选择主题吗?
可以。这项技能描述了一个手动切换开关,其选择会保存在浏览器中。
深色模式下文字会清晰可读吗?
这项技能说明,要保持足够高的对比度,达到文字的无障碍标准。
详情
作者的原始描述
Use when reviewing stylesheets, component styles, and responsive behavior related to Support dark mode with prefers-color-scheme. Check the rendered layout across breakpoints and interaction states before proposing a fix.
热度
- GitHub 星标
- 75k
- 排名
- #2807
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。