GitHub Shifts to CSS Modules, Cutting Render Times by Over Half
· GlobeWire Daily Editorial Desk · Source: github.blog

Image: Josh Black, Marie Lucca · Photo source · Resized and letterboxed to 16:9; no AI generation
Summary
GitHub’s Primer design system has completed a multi‑year migration from a CSS‑in‑JS approach to native CSS Modules. The change, rolled out with feature flags and extensive visual regression testing, delivered measurable performance gains and set the stage for a company‑wide removal of the old styling stack.
What Prompted the Move?
- In 2023 the number of UI components on key pages grew dramatically, exposing three main problems with the existing CSS‑in‑JS solution:
- Longer initial page loads – styles were generated on the client.
- Degraded server‑side rendering (SSR) – style collection shifted to the server.
- Uncontrolled style updates – more components meant more CSS churn.
- The Primer team needed a solution that eliminated both client‑ and server‑side runtime costs while keeping the system stable during migration.
Why CSS Modules?
- Allows developers to write native CSS alongside component JavaScript, preserving the familiar colocation pattern.
- Class names are local by default, preventing global selector collisions.
- Styles are compiled into static CSS files that are sent with the HTML, removing any runtime processing.
Migration Strategy
- Create a CSS Module file for each component, translating existing styles.
- Wrap the component in a feature flag that toggles between the old CSS‑in‑JS and the new module.
- Run visual regression tests to ensure pixel‑perfect parity.
- Gradually roll out the flag – first to the Primer team, then to GitHub staff, and finally to all users.
The process was repeated for every Primer component and later for the broader GitHub codebase, including the heavily used `sx` prop that allowed inline style objects.
Performance Wins
- 55 % reduction in time to server‑side render a page (by December 2024).
- 25 % faster component initialization on the client.
- Subsequent migrations of `sx` props (7,760 in April 2025) yielded 1 %‑22 % SSR improvements on individual pages.
Ongoing Work and Future Outlook
- After the Primer migration, GitHub began converting all remaining `sx` usage to CSS Modules, aided by internal codemods and a VS Code plugin.
- By June 2026 the entire GitHub front‑end runs on 100 % CSS Modules; styled‑components and the `sx` system have been fully removed.
- The team continues to monitor performance via feature‑flag metrics and plans to apply the same incremental, flag‑driven approach to any future architectural changes.
How to Verify
- Open any GitHub page and inspect the network panel – you will see only static `.css` files, no JavaScript that generates styles.
- Use the `primer-css-modules` feature flag (available in the GitHub UI settings for staff) to toggle between the old and new implementations and compare load times.
- Review the public GitHub Engineering blog post for detailed migration timelines and code samples.
--- Keywords: ["CSS Modules migration", "GitHub performance", "Primer design system", "CSS‑in‑JS replacement", "feature flag rollout", "server‑side rendering improvement", "sx prop deprecation"]
AI-assisted reporting; source claims are attributed and have not been independently verified.



