---
name: ui-web
description: Web UI - glassmorphism, Tailwind, dark mode, accessibility
---
# UI Design Skill (Web)
*Load with: base.md + react-web.md*
---
## MANDATORY: WCAG 2.1 AA Compliance
**These rules are NON-NEGOTIABLE. Every UI element must pass these checks.**
### 1. Color Contrast (CRITICAL)
```
Text Contrast Requirements:
├── Normal text (<18px): 4.5:1 minimum
├── Large text (≥18px bold or ≥24px): 3:1 minimum
├── UI components (buttons, inputs): 3:1 minimum
└── Focus indicators: 3:1 minimum
FORBIDDEN COLOR COMBINATIONS:
✗ gray-400 on white (#9CA3AF on #FFFFFF = 2.6:1) - FAILS
✗ gray-500 on white (#6B7280 on #FFFFFF = 4.6:1) - BARELY PASSES
✗ white on yellow - FAILS
✗ light blue on white - USUALLY FAILS
SAFE COLOR COMBINATIONS:
✓ gray-700 on white (#374151 on #FFFFFF = 9.2:1)
✓ gray-600 on white (#4B5563 on #FFFFFF = 6.4:1)
✓ gray-900 on white (#111827 on #FFFFFF = 16:1)
✓ white on gray-900, blue-600, green-700
```
### 2. Visibility Rules (CRITICAL)
```
ALL BUTTONS MUST HAVE:
✓ Visible background color OR visible border (min 1px)
✓ Text color that contrasts with background
✓ Minimum height: 44px (touch target)
✓ Padding: at least px-4 py-2
NEVER CREATE:
✗ Buttons with transparent background AND no border
✗ Text same color as background
✗ Ghost buttons without visible borders
✗ White text on light backgrounds
✗ Dark text on dark backgrounds
```
### 3. Required Element Styles
```tsx
// EVERY button needs visible boundaries
// PRIMARY: solid background
// SECONDARY: visible background
// GHOST: MUST have visible border
// NEVER DO THIS:
// ✗ NO BOUNDARY
// ✗ NO CONTRAST
```
### 4. Focus States (REQUIRED)
```tsx
// EVERY interactive element needs visible focus
className="focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2"
// NEVER remove focus without replacement
className="outline-none" // ✗ FORBIDDEN without ring replacement
```
### 5. Dark Mode Contrast
```
When implementing dark mode:
├── Text must be light (gray-100 to white) on dark backgrounds
├── Borders must be visible (gray-700 or lighter)
├── Never use gray-400 text on gray-900 bg (fails contrast)
└── Test BOTH modes before shipping
SAFE DARK MODE TEXT:
✓ text-white on bg-gray-900
✓ text-gray-100 on bg-gray-800
✓ text-gray-200 on bg-gray-900
UNSAFE (FAILS CONTRAST):
✗ text-gray-500 on bg-gray-900 (2.4:1)
✗ text-gray-400 on bg-gray-800 (3.1:1)
```
---
## Core Philosophy
**Beautiful UI is not decoration - it's communication.** Every visual choice should serve clarity, hierarchy, and user confidence. Default to elegance and restraint.
## Design Principles
### 1. Visual Hierarchy
```
Primary Action → Bold, high contrast, prominent
Secondary Action → Subtle, lower contrast
Tertiary/Links → Minimal, text-style
```
### 2. Spacing System (8px Grid)
```typescript
// Tailwind spacing scale - USE CONSISTENTLY
const spacing = {
xs: 'p-1', // 4px - tight internal
sm: 'p-2', // 8px - compact
md: 'p-4', // 16px - default
lg: 'p-6', // 24px - comfortable
xl: 'p-8', // 32px - spacious
'2xl': 'p-12', // 48px - section gaps
};
// Rule: More whitespace = more premium feel
// Rule: Consistent spacing > perfect spacing
```
### 3. Typography Scale
```typescript
// Limit to 3-4 font sizes per page
const typography = {
hero: 'text-4xl md:text-5xl font-bold tracking-tight',
heading: 'text-2xl md:text-3xl font-semibold',
subheading: 'text-lg md:text-xl font-medium',
body: 'text-base leading-relaxed',
caption: 'text-sm text-gray-500',
};
// Rule: Never use more than 2 font families
// Rule: Line height 1.5-1.7 for body text
```
## Glassmorphism (Web)
### Base Glass Card
```tsx
// Modern glass effect - use sparingly for emphasis
const GlassCard = ({ children, className = '' }) => (
```
## Dark Mode
### Implementation
```tsx
// Always design for both modes
// Use CSS variables or Tailwind dark: prefix
// Theme toggle
const ThemeToggle = () => {
const [dark, setDark] = useState(false);
useEffect(() => {
document.documentElement.classList.toggle('dark', dark);
}, [dark]);
return (
);
};
```
### Color Pairing
```
Light Mode Dark Mode
─────────────────────────────────
white gray-950
gray-50 gray-900
gray-100 gray-800
gray-200 gray-700
gray-900 (text) white (text)
gray-600 (secondary) gray-400
blue-600 blue-500
```
## Accessibility
### Contrast Requirements
```
WCAG AA: 4.5:1 for normal text, 3:1 for large text
WCAG AAA: 7:1 for normal text, 4.5:1 for large text
// Test: Use browser devtools or contrast checker
// Rule: Never use gray-400 on white for body text
```
### Focus States
```tsx
// Always visible focus rings
className="
focus:outline-none
focus-visible:ring-2
focus-visible:ring-blue-500
focus-visible:ring-offset-2
"
// Never remove focus styles without replacement
// ✗ outline-none (alone)
// ✓ outline-none + focus-visible:ring
```
### Screen Readers
```tsx
// Visually hidden but accessible
const srOnly = "absolute w-px h-px p-0 -m-px overflow-hidden whitespace-nowrap border-0";
// Icon buttons need labels
// Announce dynamic content
{message}
```
## Anti-Patterns
### Never Do
```
✗ More than 3 font sizes on a page
✗ Random spacing values (use 8px grid)
✗ Pure black (#000) on pure white (#fff)
✗ Colored text on colored backgrounds without checking contrast
✗ Animations longer than 500ms for UI elements
✗ Glassmorphism everywhere
✗ Drop shadows on everything
✗ Gradients on text (hard to read)
✗ Auto-playing animations that can't be stopped
✗ Removing focus indicators
✗ Gray text below 4.5:1 contrast
✗ Tiny click targets (< 44px)
```
### Common Mistakes
```tsx
// ✗ Too many shadows
className="shadow-sm shadow-md shadow-lg" // Pick ONE
// ✗ Inconsistent rounding
className="rounded-sm rounded-lg rounded-2xl" // System: sm, lg, xl, 2xl
// ✗ Competing focal points
// One primary CTA per viewport
// ✗ Over-decorated
// If it doesn't serve function, remove it
```
## Quick Reference
### Modern Defaults
```tsx
// Border radius: 12-16px (rounded-xl to rounded-2xl)
// Shadow: subtle (shadow-sm to shadow-md)
// Font: Inter, SF Pro, system-ui
// Primary: Near-black or brand color
// Transitions: 200ms ease-out
// Spacing: 8px grid (Tailwind default)
```
### Premium Feel Checklist
```
□ Generous whitespace
□ Subtle shadows (not harsh)
□ Smooth transitions on all interactions
□ Consistent border radius
□ Limited color palette (2-3 colors max)
□ Typography hierarchy (3 sizes max)
□ High-quality imagery
□ Micro-interactions on hover/focus
□ Dark mode support
```