font-size
它能做什么
这项技能检查网站 CSS 中的字号,尤其是在手机上的表现。适用于希望每位访客都能读清文字的开发者和设计师。
适用场景
- ✓当手机上的正文太小,访客不得不放大页面的时候。
- ✓当你的 CSS 使用固定像素尺寸,忽略了浏览器文字设置的时候。
- ✓当你按照文字缩放的无障碍指南检查网站的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/font-size/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请检查我的 CSS,确保移动端的文字清晰易读。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出字号声明,并标记低于 16 像素的正文或忽略用户设置的字号。它会建议使用 rem 或 em 等相对单位。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Use readable font sizes on mobile
Approximately 1 in 3 adults over 65 increases their browser's default font size. Low-vision users who cannot use screen magnifiers rely on browser font size settings as their primary accessibility tool. If font sizes are set in px only, browser font size preferences are ignored entirely. Text smaller than 16px on mobile forces all users to zoom in, breaking the page layout and triggering horizontal scroll. iOS Safari's auto-inflation of sub-12px text causes unintended layout shifts.
Quick Reference
- Body text should be at least 16px (1rem) on mobile — smaller sizes force users to zoom
- Avoid
font-sizevalues below 12px; iOS Safari ignores values below 12px and auto-inflates them - Use
remoremunits instead ofpxso text scales with the user's browser font size preference - Never set
font-size: 100%on<html>using an override that blocks user scaling — respect the browser default (16px) - WCAG 2.1 SC 1.4.4 (Resize Text, Level AA): text must be resizable up to 200% without loss of content or functionality
Check
Find all CSS font-size declarations. Flag: (1) body text or paragraph text set below 16px (or 1rem); (2) any font-size below 12px; (3) font-sizes set in px on <html> or <body> that override the browser default; (4) font-sizes that do not scale proportionally when the browser zoom is set to 200% (test in Chrome DevTools by setting font-size in browser settings or using zoom). Check that text remains readable and layout does not break at 200% zoom.
Fix
(1) Convert pixel font sizes to rem units: divide the pixel value by 16 (the browser default) — e.g., 14px becomes 0.875rem. (2) Set body text to at least 1rem (16px equivalent) on mobile. (3) Replace html { font-size: 10px } (a common reset trick) with html { font-size: 62.5% } or avoid font-size resets entirely — instead use rem values calculated from the actual 16px base. (4) If small text is intentional (captions, footnotes), ensure it is at least 0.75rem (12px) and use font-size: 0.75rem so it scales with user preferences.
Explain
WCAG 2.1 SC 1.4.4 (Resize Text) requires that text can be resized up to 200% without loss of content or functionality, except for captions and images of text. Using px units for font sizes makes text immune to browser font size settings (though not to browser zoom). Using rem or em units allows text to scale with the root font size, which the user can adjust in browser settings — this is the preferred approach. iOS Safari also has a built-in heuristic that inflates text smaller than 12px when the page is displayed in mobile view, which can cause layout inconsistencies.
Code Review
Review stylesheets, component styles, and responsive states related to Use readable font sizes on mobile. 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.
常见问题
为什么相对单位有帮助?
它们会随访客的浏览器字体设置缩放,因此需要更大字体的人也能得到相应的大字。
它接受的最小字号是多少?
这项技能建议避免低于 12 像素的字号,因为 iOS Safari 可能会自动放大它们。
它提到了哪条无障碍规则?
它提到 WCAG 1.4.4,要求文字可以放大到 200%,且不丢失内容。
详情
作者的原始描述
Use when applies to all CSS `font-size` declarations, particularly those using `px` units for body text, UI labels, and navigation. Use when auditing mobile responsiveness and accessibility compliance. Check for `font-size` in media queries targeting small screens.
热度
- GitHub 星标
- 75k
- 排名
- #2854
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。