userinterface-wiki
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUser Interface Wiki
用户界面知识库
Comprehensive UI/UX best practices guide for web interfaces. Contains 131 rules across 11 categories, prioritized by impact to guide automated code review and generation.
这是一份针对Web界面的全面UI/UX最佳实践指南,包含11个类别下的131条规则,按影响优先级排序,可用于指导自动化代码审核和生成。
When to Apply
适用场景
Reference these guidelines when:
- Implementing or reviewing animations (CSS transitions, Motion/Framer Motion)
- Choosing between springs, easing curves, or no animation
- Working with AnimatePresence and exit animations
- Writing CSS with pseudo-elements or View Transitions API
- Adding audio feedback or procedural sound to UI
- Building morphing icon components
- Animating container width/height with dynamic content
- Designing UI that respects cognitive psychology (Fitts's, Hick's, Miller's laws)
- Implementing predictive prefetching for perceived performance
- Setting up typography, OpenType features, or numeric formatting
在以下场景中参考本指南:
- 实现或审核动画(CSS过渡、Motion/Framer Motion)
- 在弹簧曲线、缓动曲线或无动画之间做选择
- 使用AnimatePresence和退出动画
- 编写包含伪元素或View Transitions API的CSS
- 为UI添加音频反馈或程序生成音效
- 构建变形图标组件
- 为包含动态内容的容器宽高添加动画
- 设计遵循认知心理学(菲茨定律、希克定律、米勒定律)的UI
- 实现可感知性能优化的预测性预加载
- 设置排版、OpenType特性或数字格式
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefixes |
|---|---|---|---|
| 1 | Animation Principles | CRITICAL | |
| 2 | Timing Functions | HIGH | |
| 3 | Exit Animations | HIGH | |
| 4 | CSS Pseudo Elements | MEDIUM | |
| 5 | Audio Feedback | MEDIUM | |
| 6 | Sound Synthesis | MEDIUM | |
| 7 | Morphing Icons | LOW | |
| 8 | Container Animation | MEDIUM | |
| 9 | Laws of UX | HIGH | |
| 10 | Predictive Prefetching | MEDIUM | |
| 11 | Typography | MEDIUM | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 动画原则 | 关键 | |
| 2 | 时间函数 | 高 | |
| 3 | 退出动画 | 高 | |
| 4 | CSS伪元素 | 中 | |
| 5 | 音频反馈 | 中 | |
| 6 | 声音合成 | 中 | |
| 7 | 变形图标 | 低 | |
| 8 | 容器动画 | 中 | |
| 9 | UX定律 | 高 | |
| 10 | 预测性预加载 | 中 | |
| 11 | 排版 | 中 | |
Quick Reference
快速参考
1. Animation Principles (CRITICAL)
1. 动画原则(关键)
- - User animations must complete within 300ms
timing-under-300ms - - Similar elements use identical timing values
timing-consistent - - Context menus: no entrance animation, exit only
timing-no-entrance-context-menu - - Use exponential ramps for natural decay, not linear
easing-natural-decay - - Linear easing only for progress indicators
easing-no-linear-motion - - Interactive elements need :active scale transform
physics-active-state - - Squash/stretch in 0.95-1.05 range
physics-subtle-deformation - - Springs for overshoot-and-settle, not easing
physics-spring-for-overshoot - - Stagger delays under 50ms per item
physics-no-excessive-stagger - - One prominent animation at a time
staging-one-focal-point - - Dim modal/dialog backgrounds
staging-dim-background - - Animated elements respect z-index layers
staging-z-index-hierarchy
- - 用户触发的动画必须在300ms内完成
timing-under-300ms - - 相似元素使用相同的时间参数
timing-consistent - - 上下文菜单:不使用入场动画,仅保留退场动画
timing-no-entrance-context-menu - - 使用指数曲线实现自然衰减,而非线性曲线
easing-natural-decay - - 线性缓动仅用于进度指示器
easing-no-linear-motion - - 交互元素需要:active状态的缩放变换
physics-active-state - - 挤压/拉伸范围控制在0.95-1.05之间
physics-subtle-deformation - - 使用弹簧曲线实现过冲后稳定的效果,而非缓动曲线
physics-spring-for-overshoot - - 序列动画的延迟间隔不超过50ms每一项
physics-no-excessive-stagger - - 同一时间仅保留一个突出的动画
staging-one-focal-point - - 模态框/对话框背景需变暗
staging-dim-background - - 动画元素需遵循z-index层级
staging-z-index-hierarchy
2. Timing Functions (HIGH)
2. 时间函数(高)
- - Gesture-driven motion (drag, flick) must use springs
spring-for-gestures - - Interruptible motion must use springs
spring-for-interruptible - - Springs preserve input energy on release
spring-preserves-velocity - - Avoid excessive oscillation in spring params
spring-params-balanced - - System state changes use easing curves
easing-for-state-change - - Entrances use ease-out
easing-entrance-ease-out - - Exits use ease-in
easing-exit-ease-in - - View transitions use ease-in-out
easing-transition-ease-in-out - - Linear only for progress/time representation
easing-linear-only-progress - - Press/hover: 120-180ms
duration-press-hover - - Small state changes: 180-260ms
duration-small-state - - User-initiated max 300ms
duration-max-300ms - - Fix slow feel with shorter duration, not curve
duration-shorten-before-curve - - No animation for high-frequency interactions
none-high-frequency - - Keyboard navigation instant, no animation
none-keyboard-navigation - - Context menus: no entrance, exit only
none-context-menu-entrance
- - 手势驱动的动效(拖拽、轻扫)必须使用弹簧曲线
spring-for-gestures - - 可中断的动效必须使用弹簧曲线
spring-for-interruptible - - 弹簧曲线需在释放时保留输入的动能
spring-preserves-velocity - - 避免弹簧参数导致过度振荡
spring-params-balanced - - 系统状态变化使用缓动曲线
easing-for-state-change - - 入场动画使用ease-out
easing-entrance-ease-out - - 退场动画使用ease-in
easing-exit-ease-in - - 视图过渡使用ease-in-out
easing-transition-ease-in-out - - 线性缓动仅用于进度/时间展示
easing-linear-only-progress - - 按压/悬停动画:120-180ms
duration-press-hover - - 小型状态变化:180-260ms
duration-small-state - - 用户触发的动画最长300ms
duration-max-300ms - - 通过缩短时长而非调整曲线来解决动效拖沓的问题
duration-shorten-before-curve - - 高频交互不使用动画
none-high-frequency - - 键盘导航即时响应,不使用动画
none-keyboard-navigation - - 上下文菜单:无入场动画,仅保留退场动画
none-context-menu-entrance
3. Exit Animations (HIGH)
3. 退出动画(高)
- - Conditional motion elements need AnimatePresence wrapper
exit-requires-wrapper - - Elements in AnimatePresence need exit prop
exit-prop-required - - Dynamic lists need unique keys, not index
exit-key-required - - Exit mirrors initial for symmetry
exit-matches-initial - - useIsPresent in child, not parent
presence-hook-in-child - - Call safeToRemove after async cleanup
presence-safe-to-remove - - Disable interactions on exiting elements
presence-disable-interactions - - Mode "wait" doubles duration; halve timing
mode-wait-doubles-duration - - Mode "sync" causes layout conflicts
mode-sync-layout-conflict - - Use popLayout for list reordering
mode-pop-layout-for-lists - - Nested AnimatePresence needs propagate prop
nested-propagate-required - - Coordinate parent-child exit durations
nested-consistent-timing
- - 条件动效元素需要AnimatePresence包裹
exit-requires-wrapper - - AnimatePresence中的元素需要exit属性
exit-prop-required - - 动态列表需要唯一key,而非索引
exit-key-required - - 退场动画与初始状态对称
exit-matches-initial - - 在子组件中使用useIsPresent,而非父组件
presence-hook-in-child - - 异步清理完成后调用safeToRemove
presence-safe-to-remove - - 禁用正在退场元素的交互
presence-disable-interactions - - 模式为"wait"时时长加倍;需将时间参数减半
mode-wait-doubles-duration - - 模式为"sync"会导致布局冲突
mode-sync-layout-conflict - - 列表重排序使用popLayout
mode-pop-layout-for-lists - - 嵌套的AnimatePresence需要propagate属性
nested-propagate-required - - 协调父子组件的退场时长
nested-consistent-timing
4. CSS Pseudo Elements (MEDIUM)
4. CSS伪元素(中)
- - ::before/::after need content property
pseudo-content-required - - Pseudo-elements over extra DOM nodes for decoration
pseudo-over-dom-node - - Parent needs position: relative
pseudo-position-relative-parent - - Z-index for correct pseudo-element layering
pseudo-z-index-layering - - Negative inset for larger hit targets
pseudo-hit-target-expansion - - View transitions need view-transition-name
transition-name-required - - Each transition name unique during transition
transition-name-unique - - Remove transition name after completion
transition-name-cleanup - - Prefer View Transitions API over JS libraries
transition-over-js-library - - Style ::view-transition-group for custom animations
transition-style-pseudo-elements - - Use ::backdrop for dialog backgrounds
native-backdrop-styling - - Use ::placeholder for input styling
native-placeholder-styling - - Use ::selection for text selection styling
native-selection-styling
- - ::before/::after需要content属性
pseudo-content-required - - 使用伪元素而非额外DOM节点实现装饰效果
pseudo-over-dom-node - - 父元素需要设置position: relative
pseudo-position-relative-parent - - 使用z-index确保伪元素层级正确
pseudo-z-index-layering - - 使用负内边距扩大点击目标区域
pseudo-hit-target-expansion - - 视图过渡需要view-transition-name
transition-name-required - - 过渡期间每个过渡名称需唯一
transition-name-unique - - 过渡完成后移除过渡名称
transition-name-cleanup - - 优先使用View Transitions API而非JavaScript库
transition-over-js-library - - 为::view-transition-group设置样式以实现自定义动画
transition-style-pseudo-elements - - 使用::backdrop为对话框背景设置样式
native-backdrop-styling - - 使用::placeholder为输入框设置样式
native-placeholder-styling - - 使用::selection为文本选中状态设置样式
native-selection-styling
5. Audio Feedback (MEDIUM)
5. 音频反馈(中)
- - Every sound must have a visual equivalent
a11y-visual-equivalent - - Provide toggle to disable sounds
a11y-toggle-setting - - Respect prefers-reduced-motion for sound
a11y-reduced-motion-check - - Allow independent volume adjustment
a11y-volume-control - - No sound on typing or keyboard nav
appropriate-no-high-frequency - - Sound for payments, uploads, submissions
appropriate-confirmations-only - - Sound for errors that can't be overlooked
appropriate-errors-warnings - - No sound on hover or decorative moments
appropriate-no-decorative - - Inform, don't punish with harsh sounds
appropriate-no-punishing - - Preload audio files to avoid delay
impl-preload-audio - - Default volume subtle (0.3), not loud
impl-default-subtle - - Reset currentTime before replay
impl-reset-current-time - - Sound weight matches action importance
weight-match-action - - Sound duration matches action duration
weight-duration-matches-action
- - 每个音效必须有对应的视觉反馈
a11y-visual-equivalent - - 提供开关以禁用音效
a11y-toggle-setting - - 尊重prefers-reduced-motion设置以控制音效
a11y-reduced-motion-check - - 允许独立调整音量
a11y-volume-control - - 打字或键盘导航时不播放音效
appropriate-no-high-frequency - - 仅在支付、上传、提交等确认场景播放音效
appropriate-confirmations-only - - 仅在无法忽略的错误或警告场景播放音效
appropriate-errors-warnings - - 悬停或装饰性场景不播放音效
appropriate-no-decorative - - 提供信息而非使用刺耳音效惩罚用户
appropriate-no-punishing - - 预加载音频文件以避免延迟
impl-preload-audio - - 默认音量设置为柔和级别(0.3),避免过大
impl-default-subtle - - 重播前重置currentTime
impl-reset-current-time - - 音效的强度与操作的重要性匹配
weight-match-action - - 音效的时长与操作的时长匹配
weight-duration-matches-action
6. Sound Synthesis (MEDIUM)
6. 声音合成(中)
- - Reuse single AudioContext, don't create per sound
context-reuse-single - - Resume suspended AudioContext before playing
context-resume-suspended - - Disconnect audio nodes after playback
context-cleanup-nodes - - Exponential ramps for natural decay
envelope-exponential-decay - - Exponential ramps target 0.001, not 0
envelope-no-zero-target - - Set initial value before ramping
envelope-set-initial-value - - Filtered noise for clicks/taps
design-noise-for-percussion - - Oscillators with pitch sweep for tonal sounds
design-oscillator-for-tonal - - Bandpass filter to shape percussive sounds
design-filter-for-character - - Click sounds: 5-15ms duration
param-click-duration - - Click filter: 3000-6000Hz
param-filter-frequency-range - - Gain under 1.0 to prevent clipping
param-reasonable-gain - - Filter Q: 2-5 for focused but natural
param-q-value-range
- - 复用单个AudioContext,不为每个音效创建新实例
context-reuse-single - - 播放前恢复暂停的AudioContext
context-resume-suspended - - 播放完成后断开音频节点
context-cleanup-nodes - - 使用指数曲线实现自然衰减
envelope-exponential-decay - - 指数曲线的目标值设为0.001而非0
envelope-no-zero-target - - 开始曲线前设置初始值
envelope-set-initial-value - - 使用滤波噪声实现点击/敲击音效
design-noise-for-percussion - - 使用带音高扫频的振荡器实现音调音效
design-oscillator-for-tonal - - 使用带通滤波器塑造打击音效的特性
design-filter-for-character - - 点击音效:5-15ms时长
param-click-duration - - 点击音效滤波器:3000-6000Hz
param-filter-frequency-range - - 增益设置低于1.0以避免削波
param-reasonable-gain - - 滤波器Q值:2-5,保证聚焦且自然
param-q-value-range
7. Morphing Icons (LOW)
7. 变形图标(低)
- - Every icon uses exactly 3 SVG lines
morphing-three-lines - - Unused lines use collapsed constant
morphing-use-collapsed - - All icons share same viewBox (14x14)
morphing-consistent-viewbox - - Rotational variants share group and base lines
morphing-group-variants - - Spring physics for grouped icon rotation
morphing-spring-rotation - - Respect prefers-reduced-motion
morphing-reduced-motion - - Instant rotation jump between non-grouped icons
morphing-jump-non-grouped - - Round stroke line caps
morphing-strokelinecap-round - - Icon SVGs are aria-hidden
morphing-aria-hidden
- - 每个图标恰好使用3条SVG线条
morphing-three-lines - - 未使用的线条使用折叠常量
morphing-use-collapsed - - 所有图标使用相同的viewBox(14x14)
morphing-consistent-viewbox - - 旋转变体共享组和基础线条
morphing-group-variants - - 分组图标的旋转使用弹簧物理效果
morphing-spring-rotation - - 尊重prefers-reduced-motion设置
morphing-reduced-motion - - 非分组图标之间的旋转使用即时跳转
morphing-jump-non-grouped - - 设置描线条帽为圆形
morphing-strokelinecap-round - - 图标SVG设置aria-hidden
morphing-aria-hidden
8. Container Animation (MEDIUM)
8. 容器动画(中)
- - Outer animated div, inner measured div; never same element
container-two-div-pattern - - Guard bounds === 0 on initial render, fall back to "auto"
container-guard-initial-zero - - Use ResizeObserver for measurement, not getBoundingClientRect
container-use-resize-observer - - Set overflow: hidden on animated container during transitions
container-overflow-hidden - - Use sparingly: buttons, accordions, interactive elements
container-no-excessive-use - - Use callback ref (not useRef) for measurement hooks
container-callback-ref
- - 使用外层动画div和内层测量div;不要使用同一个元素
container-two-div-pattern - - 初始渲染时判断边界是否为0,若为0则回退到"auto"
container-guard-initial-zero - - 使用ResizeObserver进行测量,而非getBoundingClientRect
container-use-resize-observer - - 过渡期间为动画容器设置overflow: hidden
container-overflow-hidden - - 谨慎使用:仅用于按钮、折叠面板、交互元素
container-no-excessive-use - - 使用回调ref(而非useRef)实现测量钩子
container-callback-ref
9. Laws of UX (HIGH)
9. UX定律(高)
- - Size interactive targets for easy clicking (min 32px)
ux-fitts-target-size - - Expand hit areas with invisible padding or pseudo-elements
ux-fitts-hit-area - - Minimize choices to reduce decision time
ux-hicks-minimize-choices - - Chunk data into groups of 5-9 for scannability
ux-millers-chunking - - Respond within 400ms to feel instant
ux-doherty-under-400ms - - Fake speed with skeletons, optimistic UI, progress indicators
ux-doherty-perceived-speed - - Accept messy input, output clean data
ux-postels-accept-messy-input - - Show what matters now, reveal complexity later
ux-progressive-disclosure - - Use familiar UI patterns users know from other sites
ux-jakobs-familiar-patterns - - Visual polish increases perceived usability
ux-aesthetic-usability - - Group related elements spatially with tighter spacing
ux-proximity-grouping - - Similar elements should look alike
ux-similarity-consistency - - Use boundaries to group related content
ux-common-region-boundaries - - Make important elements visually distinct
ux-von-restorff-emphasis - - Place key items first or last in sequences
ux-serial-position - - End experiences with clear success states
ux-peak-end-finish-strong - - Move complexity to the system, not the user
ux-teslers-complexity - - Show progress toward completion
ux-goal-gradient-progress - - Show incomplete state to drive completion
ux-zeigarnik-show-incomplete - - Simplify complex visuals into clear forms
ux-pragnanz-simplify
- - 交互目标设置为便于点击的尺寸(最小32px)
ux-fitts-target-size - - 使用不可见内边距或伪元素扩大点击区域
ux-fitts-hit-area - - 减少选项以缩短决策时间
ux-hicks-minimize-choices - - 将数据分成5-9组以提升可读性
ux-millers-chunking - - 400ms内响应以带来即时感
ux-doherty-under-400ms - - 使用骨架屏、乐观UI、进度指示器提升感知速度
ux-doherty-perceived-speed - - 接受不规范输入,输出整洁数据
ux-postels-accept-messy-input - - 先展示核心内容,再逐步揭示复杂功能
ux-progressive-disclosure - - 使用用户熟悉的UI模式(参考其他网站)
ux-jakobs-familiar-patterns - - 视觉优化可提升感知可用性
ux-aesthetic-usability - - 相关元素通过紧凑间距进行分组
ux-proximity-grouping - - 相似元素外观保持一致
ux-similarity-consistency - - 使用边界对相关内容进行分组
ux-common-region-boundaries - - 重要元素在视觉上突出显示
ux-von-restorff-emphasis - - 关键内容放在序列的开头或结尾
ux-serial-position - - 以清晰的成功状态结束用户体验
ux-peak-end-finish-strong - - 将复杂度转移到系统,而非用户
ux-teslers-complexity - - 展示完成目标的进度
ux-goal-gradient-progress - - 展示未完成状态以推动用户完成
ux-zeigarnik-show-incomplete - - 将复杂视觉简化为清晰形式
ux-pragnanz-simplify
10. Predictive Prefetching (MEDIUM)
10. 预测性预加载(中)
- - Trajectory prediction over hover; reclaims 100-200ms
prefetch-trajectory-over-hover - - Prefetch by intent, not viewport; avoid wasted bandwidth
prefetch-not-everything - - Use hitSlop to trigger predictions earlier
prefetch-hit-slop - - Fall back gracefully on touch devices (no cursor)
prefetch-touch-fallback - - Prefetch on keyboard navigation when focus approaches
prefetch-keyboard-tab - - Use predictive prefetching where latency is noticeable
prefetch-use-selectively
- - 使用轨迹预测而非悬停触发预加载;可节省100-200ms
prefetch-trajectory-over-hover - - 根据用户意图预加载,而非视口内所有内容;避免浪费带宽
prefetch-not-everything - - 使用hitSlop提前触发预测
prefetch-hit-slop - - 在触摸设备上优雅降级(无光标)
prefetch-touch-fallback - - 当焦点接近时,在键盘导航时触发预加载
prefetch-keyboard-tab - - 在延迟明显的场景使用预测性预加载
prefetch-use-selectively
11. Typography (MEDIUM)
11. 排版(中)
- - Tabular numbers for columns, dashboards, pricing
type-tabular-nums-for-data - - Oldstyle numbers blend into body text
type-oldstyle-nums-for-prose - - Slashed zero in code-adjacent UIs
type-slashed-zero - - Keep calt enabled for contextual glyph adjustment
type-opentype-contextual-alternates - - Enable ss02 to distinguish I/l/1 and 0/O
type-disambiguation-stylistic-set - - Leave font-optical-sizing auto for size-adaptive glyphs
type-optical-sizing-auto - - Antialiased font smoothing on retina displays
type-antialiased-on-retina - - text-wrap: balance on headings for even lines
type-text-wrap-balance-headings - - Offset underlines below descenders
type-underline-offset - - Disable font-synthesis to prevent faux bold/italic
type-no-font-synthesis
- - 表格、仪表盘、定价场景使用等宽数字
type-tabular-nums-for-data - - 正文内容使用旧式数字以融入文本
type-oldstyle-nums-for-prose - - 代码相关UI使用带斜杠的零
type-slashed-zero - - 保持calt启用以实现上下文字形调整
type-opentype-contextual-alternates - - 启用ss02以区分I/l/1和0/O
type-disambiguation-stylistic-set - - 保持font-optical-sizing为auto以实现尺寸自适应字形
type-optical-sizing-auto - - 视网膜显示屏上启用字体抗锯齿
type-antialiased-on-retina - - 标题使用text-wrap: balance实现均匀换行
type-text-wrap-balance-headings - - 下划线偏移到下行线下方
type-underline-offset - - 禁用font-synthesis以避免伪粗体/伪斜体
type-no-font-synthesis
How to Use
使用方法
Read individual rule files for detailed explanations and code examples:
rules/timing-under-300ms.md
rules/spring-for-gestures.md
rules/ux-doherty-under-400ms.md
rules/type-tabular-nums-for-data.mdEach rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
阅读单个规则文件获取详细说明和代码示例:
rules/timing-under-300ms.md
rules/spring-for-gestures.md
rules/ux-doherty-under-400ms.md
rules/type-tabular-nums-for-data.md每个规则文件包含:
- 规则重要性的简要说明
- 错误代码示例及解释
- 正确代码示例及解释
Full Compiled Document
完整编译文档
For the complete guide with all rules expanded:
AGENTS.md如需查看包含所有规则详细内容的完整指南,请查看:
",
AGENTS.md