--- name: web-design-guidelines description: UI/UX best practices and accessibility guidelines. Use when reviewing UI code, checking accessibility, auditing forms, or ensuring web interface best practices. Triggers on "review UI", "check accessibility", "audit design", "review UX", or "check best practices". license: MIT metadata: author: Web Accessibility Initiative (WAI) version: "1.0.0" --- # Web Design Guidelines Comprehensive UI/UX and accessibility guidelines for building inclusive, performant web interfaces. Contains 21 rules across 8 categories, prioritized by WCAG compliance and user impact. ## When to Apply Reference these guidelines when: - Reviewing UI code for accessibility - Implementing forms and interactions - Optimizing performance - Ensuring cross-browser compatibility - Improving user experience ## Rule Categories by Priority | Priority | Category | Impact | Prefix | |----------|----------|--------|--------| | 1 | Accessibility - Semantic Structure | CRITICAL | `a11y-` | | 2 | Accessibility - Keyboard & Focus | CRITICAL | `a11y-` | | 3 | Accessibility - Visual & Color | CRITICAL | `a11y-` | | 4 | Forms - Input & Validation | CRITICAL | `form-` | | 5 | Forms - Error Handling | HIGH | `form-` | | 6 | Forms - User Experience | MEDIUM | `form-` | | 7 | Animation & Motion | CRITICAL | `motion-` | | 8 | Performance & UX | MEDIUM | `perf-` | ## Quick Reference ### 1. Accessibility - Semantic Structure (CRITICAL) - `a11y-semantic-html` - Use semantic HTML elements - `a11y-heading-hierarchy` - Maintain proper heading hierarchy - `a11y-screen-reader` - Optimize for screen reader compatibility - `a11y-skip-links` - Provide skip links for navigation ### 2. Accessibility - Keyboard & Focus (CRITICAL) - `a11y-keyboard-nav` - Ensure full keyboard navigation - `a11y-focus-management` - Manage keyboard focus properly - `a11y-aria-labels` - Add ARIA labels to interactive elements ### 3. Accessibility - Visual & Color (CRITICAL) - `a11y-color-contrast` - Ensure sufficient color contrast - `a11y-alt-text` - Provide meaningful alt text for images ### 4. Forms - Input & Validation (CRITICAL) - `form-autocomplete` - Use autocomplete attributes for forms - `form-input-types` - Use correct input types - `form-labels` - Associate labels with form inputs ### 5. Forms - Error Handling (HIGH) - `form-error-display` - Display form errors clearly - `form-error-messages` - Provide accessible error messages - `form-validation-ux` - Design user-friendly form validation ### 6. Forms - User Experience (MEDIUM) - `form-inline-validation` - Implement smart inline validation - `form-multi-step` - Design effective multi-step forms - `form-placeholder-usage` - Use placeholders appropriately - `form-submit-feedback` - Provide clear form submission feedback ### 7. Animation & Motion (CRITICAL) - `motion-reduced` - Respect prefers-reduced-motion preference ### 8. Performance & UX (MEDIUM) - Image optimization and layout stability patterns ## Essential Guidelines ### Semantic HTML ```tsx // ❌ Div soup - no semantic meaning
Home
Page Title
Content here...
// ✅ Semantic HTML - accessible and meaningful

Page Title

Content here...

``` ### ARIA Labels ```tsx // Interactive elements need accessible names // Icon-only links // Decorative icons should be hidden ``` ### Keyboard Navigation ```tsx // All interactive elements must be keyboard accessible function Dialog({ isOpen, onClose, children }) { // Trap focus inside dialog const dialogRef = useRef(null) useEffect(() => { if (isOpen) { dialogRef.current?.focus() } }, [isOpen]) // Handle Escape key const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Escape') { onClose() } } return (
{children}
) } ``` ### Focus Styles ```tsx // ✅ Always visible focus styles // ❌ Never remove focus outlines without replacement ``` ### Form Accessibility ```tsx // ✅ Properly labeled form

We'll never share your email.

{error && ( )}
``` ### Respect Reduced Motion ```tsx // CSS @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; } } // Tailwind
Card
// JavaScript const prefersReducedMotion = window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches function animate() { if (prefersReducedMotion) { // Skip or simplify animation return } // Full animation } ``` ### Image Handling ```tsx // ✅ Proper image implementation Team collaborating around a whiteboard // ✅ Decorative images // ✅ Responsive images Hero description ``` ### Touch Targets ```tsx // ✅ Minimum 44x44px touch targets // ✅ Adequate spacing between touch targets ``` ### Color Contrast ```css /* WCAG AA requires 4.5:1 for normal text, 3:1 for large text */ /* ❌ Insufficient contrast */ .low-contrast { color: #999999; /* Gray on white: ~2.8:1 */ background: white; } /* ✅ Sufficient contrast */ .good-contrast { color: #595959; /* Darker gray: ~7:1 */ background: white; } /* ✅ Don't rely on color alone */ .error { color: #dc2626; border-left: 4px solid #dc2626; /* Visual indicator */ } ``` ### Live Regions ```tsx // Announce dynamic content to screen readers
{message}
// Toast notifications function Toast({ message }: { message: string }) { return (
{message}
) } ``` ## Output Format When auditing code, output findings in this format: ``` file:line - [category] Description of issue ``` Example: ``` src/components/Button.tsx:15 - [a11y] Missing aria-label on icon-only button src/pages/Home.tsx:42 - [perf] Image missing width/height attributes src/components/Form.tsx:28 - [form] Input missing associated label ``` ## How to Use Read individual rule files for detailed explanations and code examples: ``` rules/a11y-semantic-html.md rules/form-autocomplete.md rules/motion-reduced.md rules/_sections.md ``` Each rule file contains: - YAML frontmatter with metadata (title, impact, tags) - Brief explanation of why it matters - Incorrect code example with explanation - Correct code example with explanation - Additional context and WCAG references ## Full Compiled Document For the complete guide with all rules expanded: `AGENTS.md`