Welcome back. In our previous lesson, we established a powerful, modern styling architecture by combining the developer experience of Tailwind CSS with the native runtime dynamism of CSS Variables. We saw that this hybrid approach avoids the performance pitfalls of runtime CSS-in-JS while providing a scalable foundation.
This lesson puts that architecture to work. A design system's true power is demonstrated not just by creating consistent components, but by how easily it can adapt to different contexts. We will now design a complete, scalable theming system that addresses three critical requirements for any global, large-scale application: supporting light and dark modes, theming for multiple brands, and ensuring layouts work flawlessly for right-to-left (RTL) languages. This is a topic that frequently appears in senior-level interviews, as it tests your ability to think beyond a single use case and architect for flexibility and global scale.
The Foundation: Design Tokens & CSS Variables
As we've discussed, design tokens are the single source of truth for our visual style. In web development, these abstract tokens are transformed into a concrete, powerful implementation: CSS Custom Properties (Variables). This translation is the core mechanism that powers all the theming we'll discuss.
The following article provides an excellent refresher on the relationship between design tokens and CSS variables, and how their structure enables theming.
The developer's guide to design tokens and CSS variables - Penpot
This guide from Penpot clearly distinguishes between the abstract concept of tokens and their concrete web implementation, laying the groundwork for how we'll build our theming system.
Begin by reading the first section, The Difference Between Tokens and Variables. Focus on how the three-tiered token hierarchy (primitive, theme/semantic, component) allows changes to cascade through the system. This structure should feel familiar from our previous discussions. Next, read the sections on Dynamic Styling with CSS Variables and The Relationship. Note how CSS variables are "live and reactive" in the browser, which is the key to instantaneous theme switching. Finally, focus on the section Enabling Theming. This directly explains how token aliasing and CSS variables facilitate light/dark modes and other themes by simply redefining variable values within a specific CSS selector.
The key architectural principle is this: components are styled using semantic tokens (--color-background-primary, --text-color-default). The theme's job is to define what those semantic tokens map to. By changing the mapping, we change the theme, and the components automatically update without any change to their own styling logic.

Deep Dive 1: Architecting for Light & Dark Mode
Light and dark mode is the most common theming requirement. A senior-level implementation should be clean, performant, and require zero JavaScript-driven re-renders for the style changes themselves.
Here is the standard architecture using CSS variables:
-
Define Primitives and Light Theme Semantics at the
:rootlevel. The default theme (usually light) is defined on the:rootselector, which applies globally.:root { /* --- Primitive Tokens --- */ --color-gray-50: #F9FAFB; --color-gray-900: #111827; --color-blue-500: #3B82F6; /* --- Semantic Tokens (Light Theme) --- */ --color-surface-primary: var(--color-gray-50); --color-text-default: var(--color-gray-900); --color-action-primary: var(--color-blue-500); } -
Redefine Semantic Tokens for the Dark Theme. Using a class or
data-attribute on a high-level element (typically<html>or<body>), you override the semantic token values.html[data-theme="dark"] { /* --- Semantic Tokens (Dark Theme) --- */ --color-surface-primary: var(--color-gray-900); --color-text-default: var(--color-gray-50); /* Action color might remain the same or be adjusted for contrast */ --color-action-primary: var(--color-blue-500); } -
Components Consume Semantic Tokens. Your components (or utility classes like in Tailwind) are completely unaware of the theme. They only reference the semantic variable name.
.card { background-color: var(--color-surface-primary); color: var(--color-text-default); } .button-primary { background-color: var(--color-action-primary); } -
Toggle the Theme with Minimal JavaScript. The only JavaScript required is to change the attribute on the
<html>element. The browser's CSS engine handles the rest instantly and performantly.// Toggles between 'light' and 'dark' function toggleTheme() { const currentTheme = document.documentElement.getAttribute('data-theme'); const newTheme = currentTheme === 'dark' ? 'light' : 'dark'; document.documentElement.setAttribute('data-theme', newTheme); // Persist the user's preference in localStorage localStorage.setItem('theme', newTheme); }
This approach is highly scalable because adding a new theme (e.g., a high-contrast accessibility theme) is as simple as adding another CSS block (html[data-theme="high-contrast"] { ... }) and a way to toggle to it.
Deep Dive 2: Architecting for Multi-Brand Support
Supporting multiple brands introduces a higher level of complexity. The correct architecture depends on a crucial strategic question: are your brands closely related or fundamentally distinct? This leads to two primary architectural patterns.
Multi-Brand Design System and Figma Variable Setup | Full Tutorial
This tutorial from UI Collective is a masterclass in multi-brand design system strategy. It introduces the core concepts of "Branded House" vs. "House of Brands" and details the token architecture required to support them.
First, watch the introduction from the start to understand the two primary approaches: Branded House (e.g., Coke, Diet Coke, Coke Zero) and House of Brands (e.g., Coke, Sprite, Fanta). Next, watch the detailed explanation of the Branded House approach. Notice how it's very similar to light/dark mode, where core components and layouts are shared, and only specific styles (like primary colors) change. Pay close attention to the three-tiered token architecture: Brand (Primitives), Alias (Semantics/Roles), and Mapped (Component-specific). This structured approach is essential for managing complexity in a multi-brand system. Finally, watch the section on the House of Brands approach. The key takeaway here is that when brands are fundamentally different (different components, layouts, fonts), trying to force them into a single variable file is a "recipe for disaster." This often necessitates separate design system files or packages.
Pattern 1: Branded House
-
Scenario: Brands share the same core component library, layouts, and typography, but differ in color palettes or minor styling (e.g., border-radius). Examples: Gap, Old Navy, and Banana Republic share an e-commerce platform; Uber and Uber Eats.
-
Architecture: This is a direct extension of the light/dark mode pattern. You use a
data-brandattribute to scope brand-specific token overrides./* --- Base Semantic Tokens (e.g., Brand A) --- */ :root { --color-primary: var(--brand-a-blue); --border-radius-medium: 4px; } /* --- Brand B Overrides --- */ [data-brand="brand-b"] { --color-primary: var(--brand-b-green); --border-radius-medium: 8px; } /* --- Brand C Overrides --- */ [data-brand="brand-c"] { --color-primary: var(--brand-c-orange); --border-radius-medium: 16px; }You can even combine brand and theme selectors for maximum flexibility:
[data-brand="brand-b"][data-theme="dark"] { ... }.
Pattern 2: House of Brands
- Scenario: Brands are completely distinct. They have different logos, color palettes, typography, component styles, and potentially even different layouts. Examples: Meta (Facebook, Instagram, WhatsApp); Procter & Gamble (Tide, Gillette, Pampers).
- Architecture: A single, unified token file is often not feasible or desirable. The architectural divergence is significant:
- Separate Stylesheets: The simplest approach. Each brand has a completely separate theme file that is loaded for that brand's site.
- Separate Build Outputs: A more robust method. A build tool (like Style Dictionary) consumes a common set of primitive tokens but generates entirely different CSS outputs for each brand.
- Separate Design System Packages: The most decoupled approach. Each brand has its own design system package (
@company/brand-a-ds,@company/brand-b-ds). There might be a shared@company/base-corepackage for underlying logic or utilities, but the UI layer is distinct.
Choosing between these is a major architectural decision. Forcing a "House of Brands" scenario into a "Branded House" architecture leads to unmaintainable CSS with endless overrides and exceptions.
Deep Dive 3: A Practical Guide to RTL Layouts
Supporting right-to-left (RTL) languages like Arabic, Hebrew, and Persian is a non-negotiable for global applications. Modern CSS makes this surprisingly manageable if you build with the right concepts from the start. The core principle is to stop thinking in physical directions (left, right) and start thinking in logical, flow-relative directions (start, end).
RTL design guide for developers: Bidirectional layout done right | SimpleLocalize
This guide is an excellent, developer-focused walkthrough of implementing RTL layouts correctly.
Read the section CSS Logical Properties. This is the most critical concept. Internalize the mapping from physical (margin-left) to logical (margin-inline-start). Review the sections on Flexbox and Grid. The key insight is that flex-direction: row automatically mirrors its children in RTL. You should not use flex-direction: row-reverse to handle RTL. Study the rules for icon mirroring. Understanding which icons are directional (arrows) and which are not (search icon) is a common interview question. Finally, use the Common Mistakes Checklist as a summary of what to avoid.
The Core of RTL: Logical Properties
The foundation of RTL-compatible CSS is the dir="rtl" attribute on the <html> tag and the use of CSS logical properties.

Instead of this (which breaks in RTL):
.card {
margin-left: 16px;
padding-right: 24px;
text-align: left;
}
You write this (which works in both LTR and RTL):
.card {
margin-inline-start: 16px;
padding-inline-end: 24px;
text-align: start;
}
When the browser sees dir="rtl", it automatically maps inline-start to right and inline-end to left. You write the styles once, and they adapt correctly.
Key Rules for RTL Implementation:
- Layout: Use logical properties for all margins, paddings, borders, and positioning.
- Flexbox/Grid: Let the browser handle it.
flex-direction: rowwill correctly order items from right to left in RTL.justify-content: space-betweenalso works as expected. - Icons: Only mirror icons that convey directionality (e.g., back/forward arrows, chevrons). Use a CSS transform:
[dir="rtl"] .icon-directional { transform: scaleX(-1); }. - Animations: Be careful with horizontal
transform: translateX(...). A slide-in from the right in LTR (translateX(100%)) should be a slide-in from the left in RTL (translateX(-100%)). This often requires a CSS variable override.
:root {
--slide-in-direction: 100%;
}
[dir="rtl"] {
--slide-in-direction: -100%;
}
@keyframes slide-in {
from { transform: translateX(var(--slide-in-direction)); }
to { transform: translateX(0); }
}
Senior-Level Insight
A mid-level developer can implement a dark mode toggle. A senior engineer designs the entire styling architecture so that theming—whether for color modes, brands, or density—is a predictable and scalable capability of the system, not a series of ad-hoc hacks. They understand that the token structure and the choice between a "Branded House" or "House of Brands" model are fundamental architectural decisions with long-term consequences for maintainability and team velocity. They ensure that internationalization requirements like RTL are baked into the component library from day one using logical properties, preventing a costly and error-prone refactor down the line.
Common Mistakes in Interviews
- Ignoring RTL: Completely forgetting to mention RTL support when designing a global application is a major red flag.
- Using Physical CSS Properties: Describing a layout using
margin-leftorpadding-rightinstead of their logical counterparts (margin-inline-start,padding-inline-end). - Incorrectly Handling Flexbox for RTL: Suggesting
flex-direction: row-reverseas the solution for RTL layouts. This is a classic mistake; the browser handlesflex-direction: rowcorrectly on its own. - Lacking a Brand Strategy: Not asking clarifying questions about the relationship between brands and failing to articulate the difference between a "Branded House" and "House of Brands" architecture.
- Implementing Theming with JS Re-renders: Suggesting a theming approach that requires passing theme props down the component tree and causing re-renders, instead of leveraging the performance of CSS variables.
Conclusion
In this lesson, we designed a theming system capable of handling the complex demands of a modern, global application. We saw how a robust design token architecture, implemented with CSS variables, provides a highly performant mechanism for managing light/dark modes and multi-brand styles. By distinguishing between "Branded House" and "House of Brands" strategies, we can make informed architectural decisions that scale. Finally, by embracing CSS logical properties, we ensure our UIs are inclusive and function correctly for users of right-to-left languages.
Key Takeaways:
- CSS Variables are the Engine of Theming: They allow for instant, performant style changes driven by a single attribute toggle.
- Brand Strategy Dictates Architecture: The choice between a "Branded House" and "House of Brands" model has profound implications for your design system's structure.
- Think Logically, Not Physically: Use CSS logical properties (
*-inline-start,*-block-end) to build layouts that are automatically compatible with both LTR and RTL languages.
In our next lesson, we will continue to build on the theme of creating inclusive and robust systems by diving deep into accessibility. We'll cover how to integrate WCAG principles, ARIA roles, and focus management directly into a component library to ensure our applications are usable by everyone.