Software Engineering

How GitHub Fully Migrated github.com Away from CSS-in-JS and Achieved Peak Web Performance

The evolution of modern web development frequently mirrors the tension between developer ergonomics and raw application performance. For years, CSS-in-JS libraries reigned supreme in the React ecosystem, offering component encapsulation and dynamic styling capabilities that won over engineering teams worldwide. However, as web applications scale to serve hundreds of millions of global users, the runtime overhead of these dynamic styling engines can introduce critical bottlenecks. This reality recently prompted one of the world’s largest software development platforms to execute a massive, multi-year infrastructure overhaul. GitHub has officially completed the total migration of github.com away from CSS-in-JS, transitioning its foundational design systems and production codebase entirely to native CSS Modules.

The undertaking, spearheaded by the engineering teams behind the Primer Design System, represents a fundamental shift in how the platform builds, themes, and delivers user interfaces at scale. By eliminating client and server-side runtime costs associated with legacy styling solutions, GitHub has unlocked substantial performance gains, reducing Server-Side Rendering (SSR) latency by up to 22% across core application pages.

The Performance Toll of Scale at GitHub

At the heart of GitHub’s user interface lies the Primer Design System, a comprehensive suite of foundational components ranging from interactive buttons and informational banners to complex navigation breadcrumbs. These elements are required to maintain strict standards of accessibility, flexibility, and high performance across a staggering variety of use cases and device viewports.

By 2023, however, the sheer volume of components rendered on high-traffic pages began to escalate rapidly. This exponential growth exposed deep-seated performance vulnerabilities within GitHub’s existing CSS-in-JS architecture. Unlike traditional static stylesheets, CSS-in-JS solutions frequently inject styles dynamically via JavaScript execution during both server-side rendering and client-side hydration. As component trees grew deeper and more complex, the runtime cost required to evaluate, serialize, and inject styles began to measurably degrade page load times and increase CPU utilization.

Improving site performance by shipping more CSS

Recognizing that localized component patches would be insufficient, the Primer team determined that a structural redesign was necessary. The objective was clear: eliminate the compute overhead incurred by client and server runtimes without sacrificing the developer experience of component encapsulation. Crucially, any proposed alternative had to be implemented safely, ensuring zero downtime or visual regression for the millions of developers relying on github.com daily.

The Pivot to CSS Modules: Marrying Native CSS with Encapsulation

After evaluating numerous alternatives, GitHub engineering selected CSS Modules as the long-term strategic replacement. CSS Modules offered a compelling compromise that aligned with the team’s architectural goals. The format allows developers to author native, standard CSS files alongside their JavaScript component sources, preserving the colocation and scoping benefits popularized by CSS-in-JS.

Under the CSS Modules paradigm, all class names are treated as local by default, mitigating the risk of global selector collisions that typically plague large-scale web applications. More importantly, CSS Modules completely eliminate client and server runtime behavior. Instead of evaluating styles on the fly, styles are bundled into static CSS stylesheets distributed directly alongside the HTML payload of a page.

Despite its architectural advantages, transitioning to CSS Modules required a total rewrite of every component within the Primer Design System and every dependent component across the broader GitHub product repository. Because design systems act as the single source of truth for UI patterns across an organization, they served as the ideal vehicle to drive this massive transition at scale.

A Methodical, Multi-Year Chronology

Executing a migration of this magnitude on a live, mission-critical production platform required an exceptionally disciplined, incremental strategy. The Primer team could not simply rewrite the codebase overnight. They needed to systematically update individual components while ensuring that legacy CSS-in-JS implementations continued functioning smoothly for downstream consumers.

Improving site performance by shipping more CSS

The migration followed a rigorous lifecycle for every single component:

  1. Rewriting component styles from CSS-in-JS to CSS Modules.
  2. Integrating comprehensive feature flags to test modified components safely within production environments.
  3. Conducting rigorous monitoring to isolate performance metrics and catch regressions early.
  4. Gradually rolling out updates to internal teams and external users.

By December 2024, all foundational components within the Primer Design System had been successfully migrated to CSS Modules. The initial rewards were immediate and quantifiable, showing noticeable improvements in asset size and rendering speeds. Encouraged by these early successes, the engineering organization set its sights on a much more ambitious goal: removing CSS-in-JS support from the entire GitHub codebase.

Untangling the sx Prop and the Transition to Styled Box Zero

One of the most formidable obstacles in removing CSS-in-JS from GitHub was the widespread adoption of the sx prop. Serving as the primary mechanism for styling and customizing Primer components, the sx prop allowed developers to pass inline style objects directly into components. While beloved for its flexibility and developer velocity, the sx prop encapsulated both the best and worst aspects of CSS-in-JS, deeply coupling component markup to dynamic runtime style generation.

Before GitHub could upgrade to newer, leaner iterations of @primer/react that omitted styled-components entirely, thousands of instances of the sx prop scattered throughout the repository had to be systematically refactored.

To bridge the gap without breaking active development, engineers introduced a transitive compatibility library named @primer/styled-react. This intermediary package exposed wrapper components capable of accepting legacy sx props while simultaneously consuming the newly optimized, CSS Module-backed primitives underneath. This architectural buffer allowed product teams to migrate at their own pace without halting feature development across the platform.

Improving site performance by shipping more CSS

The Convergence of Automation and Artificial Intelligence

The subsequent phase of the migration—colloquially termed "Styled Box Zero"—commenced in April 2025. At its peak, the repository contained approximately 7,760 individual sx props requiring manual or automated refactoring.

To accelerate this tedious process, internal tooling was developed. Ian Sanders, a software engineer at GitHub, created a dedicated Visual Studio Code extension designed to assist developers with per-prop migrations. Concurrently, advanced internal codemods were deployed to automate the conversion of entire source files. Over a six-month period, a dedicated rotation of eight engineers successfully retired 6,419 props. During this phase, internal telemetry recorded Server-Side Rendering performance improvements ranging from 1% to an astounding 21.97% boost on heavy views, such as code commit pages.

The final stretch of the migration demonstrated the rapidly evolving nature of software engineering tooling. By April 2026, as GitHub integrated more sophisticated AI capabilities into its development workflows—including early deployments of advanced Copilot coding agents and automated code review systems—the remaining backlog of 895 sx props was cleared. Working alongside AI assistants, a lean team of just two engineers successfully hunted down and eliminated the final legacy props in a matter of three weeks.

Decoupling Themes and Finalizing the Re-Platforming

With the sx props successfully eradicated, the engineering team confronted the final architectural barrier preventing the total removal of styled-components: theme management. GitHub natively supports seven distinct themes, each featuring high-contrast mode variations. Historically, this dynamic theming engine relied heavily on JavaScript utilities powered by styled-components.

Fortunately, proactive planning during late 2025 had already established foundational non-styled theming variables defined natively in CSS through the @primer/css package. The final leg of the project involved stripping out the remaining JavaScript-based theme utilities, wrapping the changes in robust feature flags, and rigorously testing the platform in production.

Improving site performance by shipping more CSS

By June 2026, the transition was complete. GitHub.com was running entirely on 100% CSS Modules, officially marking the total elimination of styled-components, styled-system, and the sx prop from the core web application.

Broader Industry Implications and Future Outlook

The successful completion of GitHub’s CSS-in-JS migration offers a valuable case study for enterprise-level web engineering. As modern web applications grow increasingly complex, the hidden performance penalties of dynamic runtime styling solutions are drawing heightened scrutiny across the software development industry.

By strategically replacing runtime style injection with static, build-time CSS Modules, GitHub has demonstrated that organizations do not need to sacrifice developer ergonomics to achieve optimal web performance. The combination of disciplined incremental rollout strategies, robust feature flagging, and modern AI-assisted refactoring tools has provided a blueprint for large-scale legacy modernization. As web performance increasingly correlates directly with user retention and operational efficiency, GitHub’s architectural pivot underscores a broader industry trend toward returning to native, performant web standards.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button