css-custom-properties
它能做什么
这项技能检查样式表中是否有应该改为共享设计令牌的硬编码值。适合希望主题和全局样式修改变得简单的开发者。
适用场景
- ✓当同一个颜色或间距值出现在许多地方时。
- ✓当你想添加暗色模式或新的品牌主题时。
- ✓当修改一个设计值需要编辑许多行代码时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/css-custom-properties/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请把我样式表中重复出现的品牌颜色和间距值,提取为共享的自定义属性。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会在根元素上把重复出现的值定义为自定义属性,并把每处硬编码的值替换为 var 引用,必要时提供备用值。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Use CSS custom properties for design tokens
Hard-coded color values and magic numbers scattered across CSS files make global changes (a rebrand, a dark mode, a spacing adjustment) require finding and updating dozens of individual lines. Custom properties centralize these values so one change propagates everywhere — and enable runtime theming that preprocessor variables cannot.
Quick Reference
- Define reusable values as --variable-name on :root
- Custom properties cascade and inherit — they can be overridden at any scope
- Use var(--name, fallback) to provide fallback values
- Custom properties are runtime values — JavaScript can read and write them
Check
Find hard-coded color values, spacing values, and font sizes in this CSS file that should be replaced with CSS custom properties.
Fix
Extract repeated and meaningful values into CSS custom properties on :root and replace all usages with var() references.
Explain
Explain CSS custom properties: how they differ from preprocessor variables, how cascade and inheritance work, and how to use them for theming.
Code Review
Review stylesheets, component styles, and responsive states related to Use CSS custom properties for design tokens. 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/css-custom-properties
常见问题
自定义属性与预处理器变量有什么不同?
这项技能说明,它们是可以在任何作用域中被覆盖的运行时值,并且可以被 JavaScript 读取或修改。
它们能帮助实现暗色模式吗?
可以。这项技能说明,它们能实现预处理器变量无法做到的运行时主题切换。
备用值有什么作用?
如果没有设置该自定义属性,它会提供一个备用值。
详情
作者的原始描述
Use when reviewing stylesheets, component styles, and responsive behavior related to Use CSS custom properties for design tokens. Check the rendered layout across breakpoints and interaction states before proposing a fix.
热度
- GitHub 星标
- 75k
- 排名
- #2797
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。