Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
71

Frontend System Design · Lesson 71 of 86 · 4 min

Theming and Customization in Design Systems

This topic tests your ability to balance consistency and flexibility, a core trade-off in any scalable system.

After this lesson, you'll be able to articulate a clear strategy for theming a component library, defend your choice of technology, and explain how to handle common requirements like dark mode and white-labeling.

Choose Your Theming Strategy

You have two modern options: CSS custom properties (variables) or CSS-in-JS.

CSS variables are the baseline. They are native to the browser, have zero runtime cost, and work with any framework. You define your theme on a root element, and components consume them with var(). Switching themes is as simple as changing a data-theme attribute on a parent element.

CSS-in-JS libraries like Emotion or Styled Components use JavaScript objects for themes, passed down via React Context. This gives you the full power of JavaScript to create dynamic or computed styles. For example, you can generate a 10-step color palette from a single base color.

This power comes at a cost: increased bundle size, runtime overhead to serialize styles, and framework lock-in.

In an interview, frame this as a trade-off. Start with CSS variables for their performance and simplicity. Argue that you'd only introduce a CSS-in-JS theming solution if the design requirements call for complex, programmatic style logic that CSS cannot handle alone. A great answer suggests combining them: use a CSS-in-JS ThemeProvider to set CSS variables on a component's root node, getting the best of both worlds.

Structure Your Theme with Design Tokens

A theme is a contract. It's a collection of design decisions, called "tokens," that your components will consume. Don't just invent them as you go; define them upfront.

Your theme object or list of CSS variables should cover these categories:

  • Colors: Backgrounds, text, borders, interactive states (hover, focus).
  • Typography: Font families, sizes, weights, line heights.
  • Spacing: A scale for margins, padding, and gaps (e.g., 4px, 8px, 16px).
  • Sizing: Consistent heights and widths for elements like inputs.
  • Shadows, border radii, z-indices.

The trap: Using literal names for tokens. A token named --brand-blue is a problem when you need to support a second brand whose primary color is green. Name tokens by their role, not their value. Use --color-interactive-default or --background-surface-primary. This decouples the token's purpose from its specific implementation in any given theme.

Apply the Theme with CSS Variables

This is the most direct and debuggable way to implement theming. You define a default set of variables, typically under :root, and then override them for different themes using an attribute selector.

The JavaScript to switch themes is trivial: document.body.setAttribute('data-theme', 'dark').

/* Define the contract and the default (light) theme */
:root {
  --color-background: #ffffff;
  --color-text-primary: #1a1a1a;
  --color-interactive: #007bff;
  --spacing-md: 16px;
  --border-radius-default: 4px;
}

/* Define the dark theme overrides */
[data-theme='dark'] {
  --color-background: #1a1a1a;
  --color-text-primary: #f0f0f0;
  --color-interactive: #61dafb;
}

/* A component consuming the tokens */
.button {
  background-color: var(--color-interactive);
  color: var(--color-background); /* Note: color choice depends on contrast */
  padding: 8px var(--spacing-md);
  border-radius: var(--border-radius-default);
  border: none;
  cursor: pointer;
}

This approach also plays nicely with user preferences. You can use the prefers-color-scheme media query to set the default theme without any JavaScript at all.

Provide Controlled Customization

Theming provides consistency. Customization provides flexibility. Your job is to offer just enough flexibility without letting consumers break the system's integrity.

Styles should be applied in a clear order of precedence. This is the hierarchy you should enforce:

The best way to provide customization is through a limited set of props. A <Button> component shouldn't have props for color, backgroundColor, and padding. It should have props for variant (primary, destructive) and size (small, medium). These props map to a pre-approved set of styles that align with the design system.

For true one-off situations, provide an escape hatch like a style prop or, in CSS-in-JS, a css prop. This signals that the developer is intentionally deviating from the design system and taking responsibility for the result. Make the right thing easy, and the exceptional thing possible but explicit.

Answer the "White-Labeling" Question

A common interview prompt is: "How would you design a system to support multiple brands on the same page?" This is a test of your understanding of style scoping.

The CSS variables approach handles this well. Instead of applying data-theme to the <body>, you apply it to the root container of each branded section.

<div data-theme="brand-a">
  <!-- All components inside here get Brand A's theme -->
  <Button>Click me</Button>
</div>

<div data-theme="brand-b">
  <!-- All components inside here get Brand B's theme -->
  <Button>Click me</Button>
</div>

Because CSS variables are inherited and scoped to the DOM tree, the styles apply only within their respective containers. This is difficult to achieve with build-time tools like Sass and can be complex to manage with global ThemeProvider components from CSS-in-JS libraries. Being able to explain this specific pattern demonstrates a deep understanding of CSS architecture.

Try it

Take a component you've built for a personal project. Refactor it to use CSS variables for all hardcoded color, font-size, and spacing values. Define these variables in a :root selector. Then, add a [data-theme='dark'] rule that overrides the color variables to test your implementation.

Next: We'll cover how to build these systems inclusively in Accessibility in Component Libraries.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Atomic Design for Component Libraries

Next

Accessibility in Component Libraries