UI Design Fundamentals
The definitive guide for building production-grade web interfaces. Covers the full stack of design decisions from layout to motion.
WHEN To Use
- - Designing new UI components or pages
- Building landing pages, dashboards, or applications
- Reviewing code for design quality
- Creating distinctive interfaces that avoid generic aesthetics
- Implementing accessibility requirements
KEYWORDS
ui design, web design, layout, typography, color palette, spacing, visual hierarchy, responsive design, accessibility, motion design, component design, design tokens, frontend, css, tailwind
Design Philosophy
The 80/20 of Design Quality
| Factor | Impact | Time Investment |
|---|
| Typography | 40% | Choose 1-2 fonts well |
| Spacing |
25% | Use consistent scale |
|
Color | 20% | Limit palette, ensure contrast |
|
Everything else | 15% | Shadows, borders, motion |
Focus on typography and spacing first. They're 65% of perceived quality.
Commit to a Direction
Mediocrity is forgettable. Pick an extreme:
| Direction | Characteristics | Use When |
|---|
| Brutally Minimal | Stark, essential, nothing extra | Developer tools, productivity |
| Luxury/Refined |
Premium, subtle elegance | High-end products, fashion |
|
Playful | Fun, bright, approachable | Consumer apps, games |
|
Editorial | Type-forward, grid-based | Content sites, magazines |
|
Industrial | Function-forward, robust | B2B, enterprise |
Layout
Grid vs Flexbox Decision
| Layout Need | Tool | Why |
|---|
| Page-level structure | CSS Grid (grid-template-areas) | Named regions, explicit control |
| Navigation bars |
Flexbox | Single-axis,
gap spacing |
| Card grids | Grid (
auto-fill/
auto-fit) | Responsive without media queries |
| Centering | Grid (
place-items: center) | Shortest, most reliable |
| Sidebar + content | Grid (
250px 1fr) | Fixed + fluid |
| Stacking/overlaps | Grid +
grid-area: 1/1 | No
position: absolute needed |
Container Strategy
CODEBLOCK0
Common Layout Mistakes
| Mistake | Problem | Fix |
|---|
| Mixing container widths | Inconsistent alignment | Use single max-w-* value |
| Content behind fixed navbar |
Hidden content | Add
pt-[navbar-height] |
| No mobile padding | Edge-to-edge text | Add
px-4 minimum |
| Centered everything | Weak hierarchy | Left-align body text |
Typography
Typography carries 90% of a design's personality.
Font Pairing by Context
| Context | Display Font | Body Font | Example |
|---|
| Editorial | High-contrast serif | Neutral humanist | Playfair + Source Sans |
| SaaS |
Geometric sans | Matching sans | DM Sans + DM Mono |
| Luxury | Thin modern serif | Elegant sans | Cormorant + Jost |
| Developer | Monospace display | Monospace body | JetBrains Mono + IBM Plex |
| Playful | Rounded/quirky | Clean readable | Nunito + Outfit |
Type Scale (1.25 ratio)
CODEBLOCK1
Typography Rules
| Rule | Value | Why |
|---|
| Minimum body size | 16px | Below is hard to read |
| Body line-height |
1.5-1.75 | Improves readability |
| Heading line-height | 1.1-1.2 | Tighter for large text |
| Line length | 60-75 characters | Optimal reading |
| Paragraph spacing | 1.5em | Clear separation |
Typography Mistakes
| Mistake | Problem | Fix |
|---|
| System fonts only | Generic look | Use Google Fonts or variable fonts |
| Too many fonts |
Visual chaos | Max 2 families |
| Weak weight contrast | Poor hierarchy | Bold headings (600+), regular body |
| Long lines | Hard to read | Add
max-w-prose (65ch) |
Color
Building a Palette
Every palette needs five functional roles:
| Role | Purpose | Usage |
|---|
| Primary | Brand identity | Buttons, links, active states |
| Neutral |
Text, backgrounds | Body text, cards, dividers |
|
Accent | Secondary actions | Tags, badges, highlights |
|
Semantic | Feedback | Success/warning/error states |
|
Surface | Layered backgrounds | Cards, modals, overlays |
Surface Layering (Dark Mode)
Create depth through lightness, not shadows:
CODEBLOCK2
Contrast Requirements (WCAG)
| Text Size | Minimum Ratio | Enhanced (AAA) |
|---|
| Normal text (<18px) | 4.5:1 | 7:1 |
| Large text (≥18px bold, ≥24px) |
3:1 | 4.5:1 |
| UI components | 3:1 | — |
Color Mistakes
| Mistake | Problem | Fix |
|---|
| Purple gradient on white | "AI aesthetic" cliché | Use intentional brand colors |
| Low contrast text |
Accessibility fail | Test with contrast checker |
| Color-only indicators | Colorblind users excluded | Add icons/text |
| Too many colors | Visual noise | 3-5 colors maximum |
| Light gray text on white | Unreadable |
slate-600 minimum |
Spacing
8px Base Unit Scale
CODEBLOCK3
Spacing Rules
| Rule | Implementation |
|---|
Use gap not margins | INLINECODE14 |
| Consistent padding |
Same values on all cards/sections |
| More space between groups | Less space within groups (Gestalt) |
| No arbitrary values | Only use scale tokens |
Spacing Mistakes
| Mistake | Problem | Fix |
|---|
| Arbitrary pixel values | Inconsistent rhythm | Use spacing scale only |
| Margin on children |
Margin collapse bugs | Use
gap on parent |
| Equal spacing everywhere | No visual grouping | More between, less within |
| Tight mobile padding | Cramped feeling | Minimum
p-4 on mobile |
Visual Hierarchy
Guide the eye through deliberate contrast.
Hierarchy Techniques
| Technique | How | Impact |
|---|
| Size | Hero 3-4x body | Immediate focal point |
| Weight |
Bold headings, regular body | Scannability |
|
Color | Primary vs muted | Information layers |
|
Space | Isolation creates emphasis | Draws attention |
|
Position | Top-left anchors reading | Natural flow |
Card Hierarchy Pattern
CODEBLOCK4
Responsive Design
Breakpoint Strategy
| Breakpoint | Target | Key Changes |
|---|
| < 640px | Mobile | Single column, stacked nav, 44px touch targets |
| 640-1024px |
Tablet | Two columns, collapsible sidebars |
| 1024-1440px | Desktop | Full layout, hover enabled |
| > 1440px | Wide | Max-width container, prevent ultra-wide lines |
Fluid Techniques
CODEBLOCK5
Responsive Mistakes
| Mistake | Problem | Fix |
|---|
| No viewport meta | Broken mobile | Add INLINECODE17 |
| Fixed widths |
Overflow on mobile | Use
max-w-* and
% |
| Tiny touch targets | Frustrating taps | Minimum 44x44px |
| Hidden horizontal scroll | Broken layout | Test at 375px width |
Accessibility
Accessibility is not optional.
Critical Requirements
| Requirement | Implementation | Standard |
|---|
| Color contrast | 4.5:1 normal, 3:1 large | WCAG 2.1 AA |
| Keyboard navigation |
Tab order matches visual | WCAG 2.1.1 |
| Focus indicators | Visible
:focus-visible ring | WCAG 2.4.7 |
| Semantic HTML |
<button>,
<nav>,
<main> | WCAG 1.3.1 |
| Alt text | Descriptive for images | WCAG 1.1.1 |
| Motion safety |
prefers-reduced-motion | WCAG 2.3.3 |
| Touch targets | 44×44px minimum | WCAG 2.5.8 |
Focus Styles
CODEBLOCK6
Motion Safety
CODEBLOCK7
Motion & Animation
Use motion to communicate, not decorate.
Timing Guidelines
| Interaction | Duration | Easing |
|---|
| Button hover | 150ms | ease-out |
| Modal open |
250ms | ease-out |
| Modal close | 200ms | ease-in |
| Page transition | 300ms | ease-in-out |
| Stagger delay | 50-80ms per item | — |
| Micro-feedback | 100ms | ease-out |
Staggered Entrance
CODEBLOCK8
Motion Mistakes
| Mistake | Problem | Fix |
|---|
| Animating width/height | Performance hit | Use transform only |
| > 500ms duration |
Feels sluggish | 150-300ms for most |
| Motion everywhere | Overwhelming | Focus on entrances/exits |
| No reduced-motion | Accessibility fail | Always check preference |
Component States
Every interactive element needs clear states.
| State | Visual Treatment |
|---|
| Default | Base styling |
| Hover |
Subtle background/shadow shift |
|
Active/Pressed | Slight inset, reduced shadow |
|
Focus | High-visibility ring |
|
Disabled | 50% opacity,
not-allowed cursor |
|
Loading | Spinner or skeleton |
Button Example
CODEBLOCK9
Design Tokens Architecture
Structure tokens in three layers:
CODEBLOCK10
This allows theme switching by remapping Layer 2 only.
Pre-Delivery Checklist
Typography
- - [ ] Intentional font pairing (not system defaults)
- [ ] Consistent type scale
- [ ] Line length ≤ 75 characters
- [ ] 16px minimum body text
Color
- - [ ] Cohesive palette (3-5 colors)
- [ ] WCAG contrast met (4.5:1 normal, 3:1 large)
- [ ] Semantic colors defined
- [ ] Dark mode tested (if applicable)
Spacing
- - [ ] Consistent rhythm using scale
- [ ] No arbitrary pixel values
- [ ] Proper mobile padding
Hierarchy
- - [ ] Clear visual flow
- [ ] Primary action obvious
- [ ] Information layered by importance
Responsive
- - [ ] Mobile tested (375px)
- [ ] No horizontal overflow
- [ ] Touch targets ≥ 44px
Accessibility
- - [ ] Keyboard navigable
- [ ] Focus visible
- [ ] Screen reader tested
- [ ] Motion-safe
States
- - [ ] Hover on all interactive elements
- [ ] Focus-visible on all focusable
- [ ] Loading states for async
- [ ] Error states for forms
Performance
- - [ ] Images optimized (WebP, srcset)
- [ ] Fonts subset
- [ ] Animations use
transform/ INLINECODE28
NEVER Do
- 1. NEVER skip contrast checking — Test every text/background combination
- NEVER use color alone — Always pair with icons/text for meaning
- NEVER remove focus outlines — Unless replacing with visible alternative
- NEVER use arbitrary spacing — Stick to the scale
- NEVER animate layout properties — Only
transform and INLINECODE30 - NEVER ignore reduced-motion — Always check the preference
- NEVER center everything — Left-align body text
- NEVER use tiny touch targets — 44px minimum
- NEVER use low-contrast text —
slate-600 minimum on white - NEVER use generic system fonts — Choose intentional typography
Related Skills
- -
ui-ux-pro-max — Searchable design databases with CLI - INLINECODE33 — Creative aesthetics, avoiding "AI slop"
- INLINECODE34 — Applying themes to artifacts
- INLINECODE35 — Token architecture and theming
UI设计基础
构建生产级Web界面的权威指南。涵盖从布局到动效的完整设计决策栈。
何时使用
- - 设计新的UI组件或页面
- 构建落地页、仪表盘或应用程序
- 审查代码的设计质量
- 创建避免千篇一律的独特界面
- 实现无障碍需求
关键词
UI设计,网页设计,布局,排版,调色板,间距,视觉层次,响应式设计,无障碍设计,动效设计,组件设计,设计令牌,前端,CSS,Tailwind
设计理念
设计质量的80/20法则
| 因素 | 影响 | 时间投入 |
|---|
| 排版 | 40% | 精心选择1-2种字体 |
| 间距 |
25% | 使用一致的缩放比例 |
|
颜色 | 20% | 限制调色板,确保对比度 |
|
其他所有 | 15% | 阴影、边框、动效 |
优先关注排版和间距。它们占据了感知质量的65%。
坚持一个方向
平庸意味着被遗忘。选择一个极端:
| 方向 | 特征 | 适用场景 |
|---|
| 极致简约 | 冷峻、本质、无冗余 | 开发者工具、生产力应用 |
| 奢华/精致 |
高端、细腻优雅 | 高端产品、时尚 |
|
趣味性 | 有趣、明亮、亲和 | 消费类应用、游戏 |
|
编辑风格 | 文字优先、基于网格 | 内容网站、杂志 |
|
工业风格 | 功能优先、坚固 | B2B、企业应用 |
布局
网格 vs Flexbox 决策
| 布局需求 | 工具 | 原因 |
|---|
| 页面级结构 | CSS Grid (grid-template-areas) | 命名区域,显式控制 |
| 导航栏 |
Flexbox | 单轴,gap 间距 |
| 卡片网格 | Grid (auto-fill/auto-fit) | 无需媒体查询即可响应 |
| 居中 | Grid (place-items: center) | 最简洁、最可靠 |
| 侧边栏+内容 | Grid (250px 1fr) | 固定+流体 |
| 堆叠/重叠 | Grid + grid-area: 1/1 | 无需 position: absolute |
容器策略
css
/ 标准内容宽度 /
.container {
width: 100%;
max-width: 1280px;
margin-inline: auto;
padding-inline: clamp(1rem, 5vw, 3rem);
}
/ 全宽出血,内容受限 /
.full-bleed {
width: 100vw;
margin-left: calc(50% - 50vw);
}
常见布局错误
| 错误 | 问题 | 修复 |
|---|
| 混合使用容器宽度 | 对齐不一致 | 使用单一 max-w-* 值 |
| 内容位于固定导航栏后方 |
内容被遮挡 | 添加 pt-[navbar-height] |
| 移动端无内边距 | 文字贴边 | 至少添加 px-4 |
| 所有内容居中 | 层次感弱 | 正文左对齐 |
排版
排版承载了设计90%的个性。
按场景的字体搭配
| 场景 | 展示字体 | 正文字体 | 示例 |
|---|
| 编辑风格 | 高对比度衬线体 | 中性人文体 | Playfair + Source Sans |
| SaaS |
几何无衬线体 | 匹配的无衬线体 | DM Sans + DM Mono |
| 奢华 | 细现代衬线体 | 优雅无衬线体 | Cormorant + Jost |
| 开发者 | 等宽展示字体 | 等宽正文字体 | JetBrains Mono + IBM Plex |
| 趣味性 | 圆润/奇特 | 清晰易读 | Nunito + Outfit |
字号比例(1.25比例)
css
--text-xs: 0.64rem; / 10px - 说明文字 /
--text-sm: 0.8rem; / 13px - 次要文字 /
--text-base: 1rem; / 16px - 正文 /
--text-lg: 1.25rem; / 20px - 引导文字 /
--text-xl: 1.563rem; / 25px - h4 /
--text-2xl: 1.953rem; / 31px - h3 /
--text-3xl: 2.441rem; / 39px - h2 /
--text-4xl: 3.052rem; / 49px - h1 /
排版规则
| 规则 | 数值 | 原因 |
|---|
| 最小正文字号 | 16px | 更小难以阅读 |
| 正文行高 |
1.5-1.75 | 提高可读性 |
| 标题行高 | 1.1-1.2 | 大号文字更紧凑 |
| 行长度 | 60-75个字符 | 最佳阅读体验 |
| 段落间距 | 1.5em | 清晰分隔 |
排版错误
| 错误 | 问题 | 修复 |
|---|
| 仅使用系统字体 | 千篇一律 | 使用Google Fonts或可变字体 |
| 字体过多 |
视觉混乱 | 最多2种字族 |
| 字重对比不足 | 层次感差 | 标题加粗(600+),正文常规 |
| 行过长 | 难以阅读 | 添加 max-w-prose(65ch) |
颜色
构建调色板
每个调色板需要五个功能角色:
| 角色 | 用途 | 使用场景 |
|---|
| 主色 | 品牌标识 | 按钮、链接、激活状态 |
| 中性色 |
文字、背景 | 正文、卡片、分隔线 |
|
强调色 | 次要操作 | 标签、徽章、高亮 |
|
语义色 | 反馈 | 成功/警告/错误状态 |
|
表面色 | 分层背景 | 卡片、模态框、覆盖层 |
表面分层(深色模式)
通过亮度而非阴影创造深度:
css
:root {
--surface-0: hsl(220 15% 8%); / 页面背景 /
--surface-1: hsl(220 15% 12%); / 卡片 /
--surface-2: hsl(220 15% 16%); / 凸起元素 /
--surface-3: hsl(220 15% 20%); / 弹出框/模态框 /
}
对比度要求(WCAG)
| 文字大小 | 最低比例 | 增强(AAA) |
|---|
| 正常文字(<18px) | 4.5:1 | 7:1 |
| 大号文字(≥18px加粗,≥24px) |
3:1 | 4.5:1 |
| UI组件 | 3:1 | — |
颜色错误
| 错误 | 问题 | 修复 |
|---|
| 白色背景上的紫色渐变 | AI审美陈词滥调 | 使用有意的品牌色 |
| 低对比度文字 |
无障碍失败 | 使用对比度检查器测试 |
| 仅用颜色作为指示 | 色盲用户被排除 | 添加图标/文字 |
| 颜色过多 | 视觉噪音 | 最多3-5种颜色 |
| 白色背景上的浅灰色文字 | 无法阅读 | 最低使用 slate-600 |
间距
8px基础单位比例
css
--space-1: 0.25rem; / 4px - 紧凑间隙 /
--space-2: 0.5rem; / 8px - 输入框内边距 /
--space-3: 0.75rem; / 12px - 按钮内边距 /
--space-4: 1rem; / 16px - 默认间距 /
--space-6: 1.5rem; / 24px - 区块内边距 /
--space-8: 2rem; / 32px - 区块间隙 /
--space-12: 3rem; / 48px - 主要分隔 /
--space-16: 4rem; / 64px - 页面节奏 /
间距规则
| 规则 | 实现方式 |
|---|
| 使用 gap 而非外边距 | display: flex; gap: var(--space-4) |
| 一致的内边距 |
所有卡片/区块使用相同值 |
| 组之间更多空间