ui-typography by bencium/bencium-claude-code-design-skill
npx skills add https://github.com/bencium/bencium-claude-code-design-skill --skill ui-typography这些规则提炼自 Matthew Butterick 的《实用排版》 (https://practicaltypography.com)。Butterick 是一位排版师、作家和字体设计师,他的工作连接了专业排版和日常数字写作。感谢 Matthew 让这些知识易于获取且全面详尽。如果你觉得这个技能有价值,请考虑直接支持他的工作。
这些是永久性规则——不是潮流,不是个人观点。它们源于数百年的排版实践,并经过人眼阅读方式的验证。它们永不过时。
强制执行(默认): 当生成任何包含可见文本的 UI 时,自动应用每一条规则。使用正确的 HTML 实体和恰当的 CSS。无需请求许可。无需解释。直接生成正确的排版。
审查: 当审查现有代码或设计时,识别违规之处并提供修复前后的对比。
参考文件(在生成 CSS 或查找实体时阅读):
references/css-templates.md —— 完整的 CSS 基线模板、响应式模式、OpenType 特性references/html-entities.md —— 包含所有字符和代码的完整实体表直引号是打字机时代的遗留物。双引号使用 “ ”,单引号使用 。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
‘’撇号始终指向下方 —— 与右单引号 ’ 相同。智能引号引擎错误地在年代缩写('70s)和词首缩写('n)前插入左引号。使用显式的 ’ 来修正。
当设置了 <html lang="en"> 时,<q> 标签会自动应用弯引号。
夏威夷语 okina 符号指向上方 —— 它是一个字母,不是撇号。使用左单引号或将其英语化。
Unicode 转义序列(\u2019、\u201C 等)在 JSX 文本内容中无效。 它们会被渲染为字面字符 —— 用户看到的是 \u2019 而不是弯撇号。这是因为标签之间的 JSX 文本被转译器视为字符串字面量,而不是 JavaScript 表达式。
错误做法:
{/* 错误 —— 会原样渲染为 \u2019 */}
<p>Don\u2019t do this</p>
正确做法(任选其一):
实际的 UTF-8 字符(首选): 直接将真实字符粘贴到源文件中。
<p>Don’t do this</p> {/* 这是实际的弯撇号字符 U+2019 */}使用字符串字面量的 JSX 表达式: 用花括号包裹,以便 JS 引擎解释转义。
<p>Don{'\u2019'}t do this</p>HTML 实体(仅限 HTML 文件): 使用 ’ —— 但这在 JSX/React 中无效。
通过 CLI 进行批量修复,使用带有原始 UTF-8 字节(而非转义序列)的 sed:
CURLY=$(printf '\xe2\x80\x99') # U+2019 RIGHT SINGLE QUOTATION MARK
sed -i '' "s/don't/don${CURLY}t/g" file.tsx
在 JavaScript 数据数组和字符串字面量中,\u2019 可以正常工作,因为 JS 引擎会处理转义。此错误仅影响标签之间的 JSX 文本内容。
| 字符 | HTML | 用途 |
|---|---|---|
| - (连字符) | - | 复合词(cost-effective)、换行 |
| – (短破折号) | – | 范围(1–10)、连接(Sarbanes–Oxley Act) |
| — (长破折号) | — | 句子中断——像这样 |
切勿用 -- 或 --- 来近似替代。如果以 "from" 开头,则配对使用 "to" 而非短破折号。复合姓名用连字符(marriage);合著者用短破折号。长破折号通常紧邻文字;如果过于拥挤,可添加  。在应使用短破折号的地方不要使用斜杠。短语形容词需加连字符(five-dollar bills)。-ly 副词后不加连字符。
使用 …(…),而非三个句点。前后加空格;在紧邻文本的一侧使用 。对于中断的对话,优先使用长破折号而非省略号。
乘法使用 ×,减法使用 −。使用键盘上的 + 和 =。短破折号可作为简单的减号。尺寸:8.5″ × 14″ 使用 ×。
英尺和英寸标记 —— 弯引号规则的一个例外。必须使用直引号:英尺用 ',英寸用 "。数值之间使用 :6' 10"。
使用真实符号:© ™ ®,切勿使用 (c) (TM) (R)。™/® 是上标,前面不加空格。© 是行内符号,后接 和年份。"Copyright ©" 是冗余的 —— 用词或符号,二者选一。
§ (§) 和 ¶ (¶) 后始终跟 :§ 1782。在句子开头时拼写出来。复数形式用双符号:§§。
专有名词:重音符号是必需的(François Truffaut, Plácido Domingo)。外来词:查字典 —— 有些已本土化(naive),有些则没有(cause célèbre)。
任何标点符号后恰好一个空格。切勿两个。无可争议。两个空格会产生空白河流并破坏文本平衡。句点本身已包含视觉空白。
防止换行。用于数字引用前(§ 42、Fig. 3)、© 后(© 2025)、尊称后(Dr. Smith)、英尺/英寸数值之间。
| 需求 | 工具 |
|---|---|
| 单词间的空格 | 一个单词空格(空格键) |
| 防止换行 | |
| 新行,同一段落 | <br> |
| 新段落 | <p> 标签 |
| 新页面(打印) | page-break-before: always |
| 建议断字点 | ­ |
切勿长按空格键。切勿用双回车换行来增加间距。切勿在输出中使用制表符缩进。HTML 将所有空白折叠为单个空格( 除外)。
规则 1:粗体或斜体。互斥。切勿同时使用。规则 2:尽可能少用。如果所有内容都强调,就等于没有强调。
衬线字体:斜体用于温和强调,粗体用于强烈强调。无衬线字体:仅用粗体 —— 无衬线斜体几乎不突出。切勿将整个段落加粗。切勿使用引号进行强调。
切勿在文档或 UI 中使用下划线。这是打字机时代的变通方法。使用粗体或斜体。对于网页链接,使用微妙的样式:text-decoration-thickness: 1px; text-underline-offset: 2px。
大写字母更难阅读(均匀的矩形 vs 多变的小写轮廓)。适用于短标题、标签、说明文字。始终添加 5–12% 的字母间距。始终确保开启字距调整。切勿将整个段落大写。CSS 中使用 letter-spacing: 0.06em。
切勿伪造(缩小的常规大写字母)。对具有真实小型大写字母(OpenType smcp)的字体使用 font-variant-caps: small-caps。系统字体通常没有。添加字母间距和字距调整。
印刷:10–12pt。网页:15–25px。默认的 12pt 是打字机时代的遗留。半磅的差异也很重要。使用最小的增量进行强调。使用 clamp() 进行流畅的网页尺寸调整。
全大写和小型大写字母额外增加 5–12%。小写字母不添加。切勿将字母间距拉大到字母之间可以容纳空隙的程度。CSS:letter-spacing: 0.05em 到 0.12em。
没有例外。font-feature-settings: "kern" 1; text-rendering: optimizeLegibility;
仅在 fi/fl 视觉上冲突时必须使用。检查粗体和斜体时也要注意。否则可选。CSS:font-feature-settings: "liga" 1。
数据表格使用等宽数字("tnum")。正文使用旧式数字("onum")。默认数字适用于大多数情况。数字表格使用 font-variant-numeric: tabular-nums lining-nums。
最多 2 种字体。每种字体有固定的角色。可以混合衬线+衬线或无衬线+无衬线。很少在段落内混合字体。低对比度通常比高对比度更有效。
在设置其他任何内容之前,先设置正文。四个决定决定一切:字体、字号、行距、行长。所有其他元素都根据这些进行校准。
设计师最容易犯的第一大可读性因素。响应式网页布局的第一大缺陷。以字符数衡量,而非英寸。字母表测试:每行容纳 2–3 个小写字母表。CSS:在文本容器上使用 max-width: 65ch。
line-height: 1.2 到 1.45。单倍行距(约 117%)太紧。双倍行距(约 233%)太松。文字处理器的"单倍"和"双倍"都偏离了最佳范围。
对于比例字体,一英寸是不够的。印刷:12pt 字体下 1.5–2.0 英寸。网页:文本容器上的 max-width 加上 padding。不要害怕留白 —— 宽裕的页边距显得专业。
网页左对齐(默认)。两端对齐需要 hyphens: auto —— 浏览器引擎很粗糙。居中:谨慎使用,仅用于短标题(< 1 行)。切勿将整个文本块居中。
首行缩进: 1–4 倍字号。text-indent: 1.5em。第一段可选。段间距: 字体大小的 50–100%。margin-bottom: 0.75em。切勿使用双 <br> 标签。
hyphens: nonepage-break-after: avoid)略微减小字号和行距。缩进 2–5em。不加引号(缩进表示引用)。保持行长可读。谨慎使用 —— 长块引用表明写作懒惰。
使用语义标记(<ul>、<ol>),切勿手动添加项目符号。优先使用空心项目符号。星号作为项目符号太小。不要过度缩进。
数据本身就构成了隐含的网格。边框会增加杂乱感。仅保留表头行下方的细线。padding: 0.5em 1em。数字列使用等宽数字。数字右对齐。
首先尝试上下增加间距。边框粗细:0.5–1pt。不要使用图案边框。粗线是图表垃圾。
寡行(段落的最后一行单独出现在页面顶部)和孤行(段落的第一行单独出现在页面底部)。CSS 打印:orphans: 2; widows: 2。标题:page-break-after: avoid。对于断字引擎容易混淆的单词,使用软连字符 ­。
印刷分栏:信纸尺寸上 2–3 栏,切勿 4 栏。网页分栏:效果不佳(底部边缘不确定)。网格起指导作用,而非保证 —— 更简单的网格能强制执行更多一致性。将丑陋的内容对齐到网格上,结果仍然是丑陋的。
规则不随屏幕尺寸改变。 相同的行长、行距、层级。
font-size 和容器 widthmax-width —— 切勿让文本紧贴边缘ch 单位进行精确测量(它只测量零宽度)clamp() 进行流畅缩放:font-size: clamp(16px, 2.5vw, 20px)padding: 0 1rem现代屏幕渲染字体的效果几乎与印刷品一样好。"屏幕使用无衬线字体"的说法在 72dpi 时代是正确的,但现在已过时。衬线字体在现代屏幕上效果良好。深色模式:略微减轻字重。在 macOS 和 Windows 上测试(抗锯齿效果不同)。
每周安装次数
26
代码仓库
GitHub 星标数
94
首次出现
12 天前
安全审计
安装于
opencode24
github-copilot24
codex24
amp24
cline24
kimi-cli24
These rules are distilled from Matthew Butterick's Practical Typography (https://practicaltypography.com). Butterick is a typographer, writer, and type designer whose work bridges professional typography and everyday digital writing. Thank you, Matthew, for making this knowledge accessible and encyclopedic. If you find this skill valuable, consider supporting his work directly.
These are permanent rules — not trends, not opinions. They come from centuries of typographic practice, validated by how the human eye reads. They do not go out of style.
ENFORCEMENT (default): When generating ANY UI with visible text, apply every rule automatically. Use correct HTML entities, proper CSS. Do not ask permission. Do not explain. Just produce correct typography.
AUDIT: When reviewing existing code or design, identify violations and provide before/after fixes.
Reference files (read when generating CSS or looking up entities):
references/css-templates.md — Full CSS baseline template, responsive patterns, OpenType featuresreferences/html-entities.md — Complete entity table with all characters and codesStraight quotes are typewriter artifacts. Use “ ” for double, ‘ ’ for single.
Apostrophes always point down — identical to closing single quote ’. Smart-quote engines wrongly insert opening quotes before decade abbreviations ('70s) and word-initial contractions ('n'). Fix with explicit ’.
The <q> tag auto-applies curly quotes when <html lang="en"> is set.
Hawaiian okina points upward — it's a letter, not an apostrophe. Use opening single quote or anglicize.
Unicode escape sequences (\u2019, \u201C, etc.) do NOT work in JSX text content. They render as literal characters — the user sees \u2019 instead of a curly apostrophe. This is because JSX text between tags is treated as string literals by the transpiler, not as JavaScript expressions.
What fails:
{/* WRONG — renders literally as \u2019 */}
<p>Don\u2019t do this</p>
What works (pick one):
Actual UTF-8 characters (preferred): Paste the real character directly into the source file.
<p>Don\u2019t do this</p> {/* This is the actual curly apostrophe character U+2019 */}
JSX expression with string literal: Wrap in curly braces so the JS engine interprets the escape.
<p>Don{'\u2019'}t do this</p>
HTML entity (HTML files only): Use ’ — but this does NOT work in JSX/React.
For bulk fixes via CLI , use sed with raw UTF-8 bytes (not escape sequences):
CURLY=$(printf '\xe2\x80\x99') # U+2019 RIGHT SINGLE QUOTATION MARK
sed -i '' "s/don't/don${CURLY}t/g" file.tsx
In JavaScript data arrays and string literals , \u2019 works correctly because the JS engine processes the escape. The bug only affects JSX text content between tags.
| Character | HTML | Use |
|---|---|---|
| - (hyphen) | - | Compound words (cost-effective), line breaks |
| – (en dash) | – | Ranges (1–10), connections (Sarbanes–Oxley Act) |
| — (em dash) | — | Sentence breaks—like this |
Never approximate with -- or ---. If you open with "from", pair with "to" not en dash. Hyphen for compound names (marriage); en dash for joint authorship. Em dash typically flush; add   if crushed. No slash where en dash belongs. Hyphenate phrasal adjectives (five-dollar bills). No hyphen after -ly adverbs.
Use … (…), not three periods. Spaces before and after; use on the text-adjacent side. For interrupted dialogue, prefer em dash over ellipsis.
Use × for multiplication, − for subtraction. Use + and = from keyboard. En dash is acceptable as simple minus. Dimensions: 8.5″ × 14″ uses ×.
Foot and inch marks — the ONE exception to curly quotes. Must be STRAIGHT: ' for foot, " for inch. Use between values: 6' 10".
Use real symbols: © ™ ®, never (c) (TM) (R). ™/® are superscripts, no space before. © is inline, followed by then year. "Copyright ©" is redundant — word OR symbol, not both.
§ (§) and ¶ (¶) always followed by : § 1782. Spell out at sentence start. Double for plurals: §§.
Proper names: accents are MANDATORY (François Truffaut, Plácido Domingo). Loanwords: check dictionary — some naturalized (naive), some not (cause célèbre).
Exactly one space after any punctuation. Never two. Not debatable. Two spaces create rivers and disrupt text balance. The period already contains visual white space.
prevents line break. Use before numeric refs (§ 42, Fig. 3), after © (© 2025), after honorifics (Dr. Smith), between foot/inch values.
| Need | Tool |
|---|---|
| Space between words | One word space (spacebar) |
| Prevent line break | |
| New line, same paragraph | <br> |
| New paragraph | <p> tags |
| New page (print) | page-break-before: always |
| Suggest hyphenation point | ­ |
Never hold spacebar. Never double carriage returns for spacing. Never tabs for indentation in output. HTML collapses all whitespace to single space (except ).
Rule 1 : Bold OR italic. Mutually exclusive. Never combine. Rule 2 : Use as little as possible. If everything is emphasized, nothing is.
Serif: italic for gentle, bold for strong. Sans serif: bold only — italic sans barely stands out. Never bold entire paragraphs. Never use quotation marks for emphasis.
Never underline in a document or UI. Typewriter workaround. Use bold or italic. For web links, use subtle styling: text-decoration-thickness: 1px; text-underline-offset: 2px.
Caps are harder to read (homogeneous rectangles vs varied lowercase contour). Suitable for short headings, labels, captions. ALWAYS add 5–12% letterspacing. ALWAYS ensure kerning is on. NEVER capitalize whole paragraphs. letter-spacing: 0.06em in CSS.
Never fake (scaled-down regular caps). Use font-variant-caps: small-caps with fonts that have real small caps (OpenType smcp). System fonts lack them. Add letterspacing + kerning.
Print: 10–12pt. Web: 15–25px. The 12pt default is a typewriter relic. Half-point differences matter. Use smallest increment for emphasis. Use clamp() for fluid web sizing.
5–12% extra on ALL CAPS and small caps. Nothing on lowercase. Never spread so far apart that letters could fit in the gaps. CSS: letter-spacing: 0.05em to 0.12em.
No exceptions. font-feature-settings: "kern" 1; text-rendering: optimizeLegibility;
Mandatory only when fi/fl visually collide. Check bold and italic too. Otherwise optional. CSS: font-feature-settings: "liga" 1.
Tabular ("tnum") for data tables. Oldstyle ("onum") for body text. Default figures are fine for most uses. font-variant-numeric: tabular-nums lining-nums for numeric tables.
Max 2 fonts. Each gets a consistent role. Can mix serif+serif or sans+sans. Rarely mix within a paragraph. Lower contrast often more effective than high contrast.
Set body text BEFORE anything else. Four decisions determine everything: font, point size, line spacing, line length. All other elements calibrate against these.
The #1 readability factor designers get wrong. The #1 flaw in responsive web layouts. Measure in characters, not inches. Alphabet test: fit 2–3 lowercase alphabets per line. CSS: max-width: 65ch on text containers.
line-height: 1.2 to 1.45. Single-spaced (~117%) is too tight. Double (~233%) is too loose. Word processor "Single" and "Double" both miss the optimal range.
One inch is not enough for proportional fonts. Print: 1.5–2.0″ at 12pt. Web: max-width on text containers plus padding. Don't fear white space — generous margins look professional.
Left-align for web (default). Justified requires hyphens: auto — browser engines are crude. Centered: sparingly, only for short titles (< 1 line). Never center whole text blocks.
First-line indent : 1–4× point size. text-indent: 1.5em. Optional on first paragraph. Space between : 50–100% of font size. margin-bottom: 0.75em. Never double <br> tags.
hyphens: none on headingspage-break-after: avoid)Reduce size + line spacing slightly. Indent 2–5em. No quotation marks (indent signals the quote). Keep line length readable. Use sparingly — long block quotes signal lazy writing.
Semantic markup (<ul>, <ol>), never manual bullets. Prefer hollow bullets. Asterisks are too small for bullets. Don't over-indent.
Data creates an implied grid. Borders add clutter. Keep only thin rule under header row. padding: 0.5em 1em. Tabular figures for numeric columns. Right-align numbers.
Try space above and below first. Border thickness: 0.5–1pt. No patterned borders. Thick lines are chartjunk.
Widows (last line alone at top of page) and orphans (first line alone at bottom). CSS print: orphans: 2; widows: 2. Headings: page-break-after: avoid. Soft hyphens ­ for words that confuse hyphenation engines.
Print columns: 2–3 on letter paper, never 4. Web columns: awkward (indefinite bottom edge). Grids guide, not guarantee — simpler grids enforce more consistency. Aligning ugly to a grid still produces ugly.
The rules don't change with screen size. Same line length, line spacing, hierarchy.
font-size and container width togethermax-width on text containers — never edge-to-edge textch unit for exact measurement (only measures zero width)clamp() for fluid scaling: font-size: clamp(16px, 2.5vw, 20px)padding: 0 1rem on text containersModern screens render type nearly as well as print. "Sans serif for screens" was true for 72dpi and is now obsolete. Serif fonts work fine on modern screens. Dark mode: reduce weight slightly. Test on macOS and Windows (antialiasing differs).
Weekly Installs
26
Repository
GitHub Stars
94
First Seen
12 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode24
github-copilot24
codex24
amp24
cline24
kimi-cli24
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
122,000 周安装