Learn the Good Patterns
Real-world engineering guide on how top e-commerce websites achieve sub-1.0s LCP, zero layout shifts, impenetrable checkout security, and effortless scale.
Visual Hierarchy, WCAG 2.1 Colors & Font Performance
Applying the 60-30-10 color rule, ensuring WCAG AAA 7:1+ contrast ratios for product pricing and text, and eliminating layout shifts with font-display: swap.
The 60-30-10 Rule, AAA Contrast & Zero FOIT Typography
A world-class storefront applies the 60-30-10 color palette formula: 60% neutral background for breathing room, 30% structural contrast (dark slate text, clear cards), and 10% purposeful accent color (e.g. vibrant emerald for primary "Add to Bag" and checkout actions). Text maintains strict WCAG contrast ratios, and fonts use font-display: swap to prevent invisible text flashing.
/* 1. Tailwind CSS / Design Tokens with Guaranteed WCAG AA/AAA Contrast */
:root {
--bg-primary: #0a0f1d; /* 60% Dominant Surface */
--surface-card: #111827; /* 30% Structural Card Surface */
--text-primary: #f9fafb; /* 16.9:1 Contrast on #0a0f1d (WCAG AAA) */
--text-muted: #94a3b8; /* 6.4:1 Contrast on #0a0f1d (WCAG AA+) */
--accent-cta: #10b981; /* 10% Primary CTA Accent */
--accent-cta-text: #022c22; /* Dark ink on #10b981: 8.6:1 AAA Contrast */
}
/* 2. Zero FOIT Typography + Size-Adjust Fallback Metrics (CLS 0.00) */
@font-face {
font-family: 'Inter';
src: url('/fonts/inter-roman.woff2') format('woff2');
font-weight: 100 900;
font-display: swap; /* Renders adjusted system font immediately */
size-adjust: 100.2%;
}
/* 3. Accessible Minimum Touch Targets & Focus Ring (WCAG 2.2) */
.cta-btn { min-height: 44px; min-width: 44px; }
.cta-btn:focus-visible { outline: 2px solid #34d399; outline-offset: 2px; }Key Engineering & Business Benefits:
- Guides customer attention directly to the primary purchase call-to-action while meeting 4.5:1+ AA and 7:1+ AAA contrast rules.
- Ensures effortless legibility outdoors under direct sunlight on mobile screens and low-vision monitors.
- Prevents Flash of Invisible Text (FOIT) and font-swap Cumulative Layout Shift (CLS) using next/font or woff2 size-adjust.
The Horror Site: 1.16:1 Yellow-on-Green, Outline None & 7 External Fonts
The bad site paired neon yellow prices against pale backgrounds (1.16:1 contrast ratio—legally non-compliant in ADA/EAA markets), stripped keyboard focus outlines (* { outline: none }), and blocked first paint with 7 unhosted Google Font stylesheet requests.
<span style="color:#ffee00; background:#d9f99d; font-family:'Comic Sans MS';">
$129.00 - Best Deal (1.16:1 ratio — Fails WCAG AA 4.5:1!)
</span>How to Implement / Fix in 3 Practical Steps
Maintain >= 4.5:1 contrast for body copy (>= 7:1 AAA for pricing, alerts, and legal text) and >= 3:1 for large UI boundaries.
Self-host variable woff2 fonts (or Next.js next/font/google) with font-display: swap and preload critical weights only.
Enforce >= 44x44px hit targets on mobile checkout controls and preserve visible :focus-visible rings for keyboard shoppers.
DevTools -> Lighthouse -> Run Accessibility audit. Verify color contrast score is 100% and inspect product price elements for high contrast rating.
Finished reading this lesson?
Mark it as mastered below, or click Next Lesson to auto-complete.