CSS Modules, Panda CSS and StyleX are changing how I think about styling architecture, component libraries and performance in production React applications.
For a long time, CSS-in-JS felt like a natural evolution of styling in React.
Styles could live alongside components. Dynamic values could be derived from props. Design tokens could be shared through JavaScript. TypeScript could help enforce consistency. And developers no longer had to worry as much about naming collisions or managing large global stylesheets.
It made styling feel like part of the component model.
But as applications grew, some of the trade-offs became harder to ignore.
I have been revisiting how I think about styling architecture, particularly in applications with large component libraries, shared design systems and increasingly complex rendering requirements.
One question keeps coming up:
Are we moving away from CSS-in-JS, or are we getting better at deciding when styling work should happen?
GitHub's migration raises a bigger architectural question
GitHub published an engineering article explaining how it migrated GitHub.com away from CSS-in-JS.
The problem was not simply that the team disliked its styling solution. The existing approach was introducing costs as the number of components on a page increased.
Style initialization affected client rendering. Server side rendering had to deal with style collection. Dynamic style updates became increasingly expensive as component counts grew.
GitHub's Primer team moved its components to CSS Modules and reported a 55% reduction in server side rendering time and a 25% reduction in component initialization time.
Those are significant improvements, especially at the scale of a product like GitHub.
What I find more interesting is the engineering decision behind the migration.
The team did not replace one styling syntax with another simply because something newer existed. It identified where styling work was happening, understood the cost, and changed the architecture to remove unnecessary work from the rendering path.
That is the part worth paying attention to.
The article also describes a gradual migration using feature flags, visual regression tests and compatibility layers. This was a substantial architectural change, not a quick dependency replacement.
Read GitHub's engineering article
The distinction that matters: authoring styles versus generating styles
I think discussions about CSS-in-JS often become unnecessarily polarised.
People compare syntax, developer experience and how convenient it is to write styles inside a component. Those things matter, but they do not tell us enough about the architecture.
Consider two separate questions:
- Where do developers author styles?
- When are those styles converted into CSS that the browser can use?
These questions are related, but they are not the same.
A developer can author styles in TypeScript while having those styles extracted during the build. Another developer can write styles in a separate CSS file and have the bundler process them into production stylesheets.
The important distinction is whether the application needs to evaluate styling logic, generate rules or inject styles while rendering components.
Traditional runtime CSS-in-JS libraries can introduce work during server rendering or browser execution, depending on the library and how it is used.
Build time approaches move much of that work earlier.
This does not mean every runtime styling solution is inherently slow, or that every build time solution is automatically faster. It means the cost model is different, and that difference becomes important as an application grows.
I think this is where CSS Modules, Panda CSS and StyleX become particularly interesting.
1. CSS Modules: native CSS with component level boundaries
CSS Modules are probably the most straightforward option in this comparison.
You write ordinary CSS in a .module.css file and import it into a component. Class names are locally scoped, so the same class name can exist in different modules without creating global collisions.
For example, imagine a component that displays the current state of an operational report.
ReportSummary.tsx
import styles from "./ReportSummary.module.css"; type ReportSummaryProps = { title: string; status: "healthy" | "warning" | "critical"; description: string; }; export function ReportSummary({ title, status, description, }: ReportSummaryProps) { return ( <article className={styles.summary}> <div className={styles.heading}> <h2>{title}</h2> <span className={styles[status]}>{status}</span> </div> <p>{description}</p> </article> ); } ReportSummary.module.css
.summary { padding: 1.25rem; border: 1px solid #e5e7eb; border-radius: 0.75rem; background: white; } .heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; } .healthy { color: #15803d; } .warning { color: #a16207; } .critical { color: #b91c1c; } There is nothing particularly complicated here.
The browser receives CSS through the normal stylesheet delivery process. There is no need for a component to generate and inject a new style rule during rendering.
Where CSS Modules work well
- Applications that benefit from native CSS and straightforward component styling.
- Teams that want minimal styling infrastructure.
- Next.js applications using the App Router and React Server Components.
- Codebases where component styles are relatively self contained.
Where the trade-offs appear
CSS Modules provide scoping, but they do not provide a complete design system architecture.
You still need to establish how tokens, spacing scales, typography, themes and component variants are managed.
As a component library grows, developers can end up building their own conventions for variants and shared styling patterns.
That is not necessarily a problem. It is simply additional architecture that the team needs to own.
CSS Modules give you a solid foundation, but they do not prescribe how your design system should work.
2. Panda CSS: a design system with build time CSS generation
Panda CSS approaches the problem differently.
It provides a TypeScript based styling API while generating CSS at build time. Instead of relying on runtime style injection, Panda analyses the styles in your source code and extracts the CSS it can determine ahead of time.
This makes it particularly interesting for teams building reusable component libraries.
You get an API that feels close to styling directly inside React components, but the resulting CSS is generated before the application runs.
One of Panda's most useful concepts is the recipe.
A recipe allows a component to define a controlled set of visual variants rather than repeatedly implementing conditional styling logic.
For a report summary, the styling could be expressed as:
import { cva } from "../styled-system/css"; export const reportSummary = cva({ base: { padding: "5", borderRadius: "lg", borderWidth: "1px", background: "white", }, variants: { status: { healthy: { borderColor: "green.300", }, warning: { borderColor: "yellow.400", }, critical: { borderColor: "red.400", }, }, density: { comfortable: { padding: "5", }, compact: { padding: "3", }, }, }, defaultVariants: { status: "healthy", density: "comfortable", }, }); The component can then select its appearance through named variants.
import { reportSummary } from "./reportSummary"; export function ReportSummary({ status, density, children, }) { return ( <article className={reportSummary({ status, density })}> {children} </article> ); } This becomes useful when the same component needs to support multiple visual states across different applications.
Panda also has slot recipes for components made up of multiple styled elements. Think of an analytics card with a header, title, metadata, chart area and footer. Those parts can share a variant definition without forcing every component to manage its own collection of conditional classes.
Where Panda CSS works well
- Shared component libraries.
- Applications with a substantial design token system.
- Teams that want TypeScript authoring and build time CSS generation.
- Components with multiple variants and compound states.
- Design systems that need consistent patterns across several applications.
Where the trade-offs appear
Panda introduces a build step and a styling abstraction that the team needs to understand.
Its extraction model also has constraints. The compiler needs to be able to determine which styles should exist. If a style value is only known at runtime, the team needs to use supported techniques such as CSS variables or explicitly generated styles.
That is an important distinction when building highly dynamic interfaces.
Panda gives you more structure than CSS Modules, but that structure comes with conventions and build configuration.
For a small application, that may be unnecessary. For a shared design system, it can be a worthwhile investment.
3. StyleX: atomic CSS with compile time extraction
StyleX is particularly interesting because it takes a different route to solving the same problem.
Developed at Meta, StyleX combines JavaScript authoring with compile time style extraction and atomic CSS generation.
Instead of producing a large collection of component specific CSS declarations, it can reuse atomic declarations across components.
If several components use the same padding, font weight or colour, those declarations can share generated CSS rules.
This becomes valuable in large applications where the same styling decisions appear across many components.
A simplified example:
import * as stylex from "@stylexjs/stylex"; const styles = stylex.create({ summary: { padding: "20px", borderRadius: "12px", backgroundColor: "#ffffff", }, healthy: { borderColor: "#15803d", }, warning: { borderColor: "#a16207", }, critical: { borderColor: "#b91c1c", }, }); export function ReportSummary({ status, children }) { return ( <article {...stylex.props( styles.summary, styles[status] )} > {children} </article> ); } The example illustrates the authoring model. The actual production setup requires the StyleX compiler integration to transform style definitions and generate the corresponding CSS.
StyleX is designed to avoid runtime style injection. Its compiler generates optimised atomic CSS, while the runtime handles style composition.
Where StyleX works well
- Large applications with many shared styling declarations.
- Teams that value predictable style composition.
- Design systems that need consistent styling across a large component surface.
- Applications where reducing duplicated CSS declarations is important.
Where the trade-offs appear
StyleX is not simply a library that can be dropped into any React project without architectural consideration.
The compiler and build integration are central to how it works. Teams need to understand its supported styling model, constraints and integration requirements.
Atomic CSS also changes how developers think about generated styles. Debugging and inspecting output can feel different from working with familiar component level CSS classes.
For a large engineering organisation, those trade-offs may be justified. For a smaller team, the additional setup may not provide enough value.
Comparing the three approaches
The interesting comparison is not which syntax looks better. It is how each approach handles the needs of a growing application.
| Concern | CSS Modules | Panda CSS | StyleX |
|---|---|---|---|
| Style authoring | CSS files | TypeScript | JavaScript |
| CSS generation | Build pipeline | Build time extraction | Compile time extraction |
| Runtime style injection | No | No | No |
| Local scoping | Yes | Generated classes | Generated atomic classes |
| Design tokens | Manual conventions | Built in system | Supported through themes and variables |
| Component variants | Manual implementation | Recipes | Style composition |
| Multi part components | Manual implementation | Slot recipes | Composable styles |
| Atomic CSS | No | Yes | Yes |
| Build integration | Relatively straightforward | Requires Panda setup | Requires compiler integration |
There is no universal winner here.
CSS Modules prioritise native CSS and simplicity. Panda CSS provides a more opinionated design system toolkit. StyleX focuses on predictable composition and optimised atomic output.
The right choice depends on the constraints of the application and the team maintaining it.
What I would actually measure before choosing
This is where I think engineering teams should be more deliberate.
It is easy to compare styling libraries by writing the same component three times and deciding which API feels nicer.
That tells us something about developer experience. It tells us very little about production performance.
If I were evaluating these approaches for a production React application, I would build the same component suite with each solution.
I would include:
- An analytics summary with multiple visual states.
- A nested activity timeline.
- A data table with conditional row states.
- A filter panel with responsive layouts.
- A notification feed with different severity levels.
The components would have the same markup, content, behaviour and visual output. The only meaningful difference would be the styling implementation.
Then I would measure several things.
Build performance
How long does a clean production build take? How much does an incremental change affect build time? Does the styling compiler introduce a noticeable cost to the development workflow?
CSS output
How much CSS is generated? What is the compressed stylesheet size? How many unique rules are emitted? Does the output grow proportionally as more components and variants are introduced?
Server rendering
How much time does server rendering take? Does the styling solution introduce additional work during rendering? Are styles available in the initial HTML and stylesheet delivery path?
Browser execution
How much JavaScript is required to initialise the styling system? Is there runtime style generation or injection? How much work happens during hydration and subsequent component updates?
User experience
I would also measure LCP, INP and CLS under realistic conditions. These metrics help reveal whether the styling architecture contributes to the experience users actually see.
I would run production builds, repeat measurements, control the environment and compare medians rather than relying on a single run.
Most importantly, I would separate the cost of generating styles from the cost of composing styles in JavaScript. They are different parts of the system and should be measured independently.
I have not run this comparison yet, so I would not attach performance numbers to it. The methodology is what I would use to make the decision rather than assuming that one library is faster because of how it describes its architecture.
What I would choose for a production application
My preference would depend on the kind of system I was building.
For a conventional application with a relatively small component library, I would be comfortable choosing CSS Modules. Native CSS is powerful, the mental model is straightforward and the amount of additional infrastructure is limited.
For a product with multiple applications sharing a design system, I would seriously consider Panda CSS. Recipes, tokens and slot recipes provide useful abstractions when consistency across a large component surface becomes important.
For a large application with substantial component reuse and a team comfortable with compiler driven tooling, I would evaluate StyleX. Its atomic output and composition model are compelling, particularly when the same styling declarations are repeated across a large codebase.
I would also consider the existing ecosystem.
How does the solution integrate with the framework? How easy is it to migrate existing components? Can the team debug generated output? What happens when a component needs a style that cannot be determined at build time? How does the system behave when multiple applications consume the same design system?
These questions matter more than whether the styling API looks elegant in a small example.
CSS-in-JS is not dead. The cost model is changing.
I do not think the industry is abandoning the idea of authoring styles alongside components.
That developer experience remains valuable.
What is changing is where the work happens.
The shift towards build time extraction, static CSS generation and atomic output reflects a broader architectural preference: move work out of the critical rendering path when it can be done ahead of time.
GitHub's migration is a useful example of what happens when the cost of a styling abstraction becomes significant at scale. It is not proof that CSS Modules are the right answer for every application, or that every CSS-in-JS approach has the same performance characteristics.
The more useful lesson is to understand the work your styling architecture asks the browser and server to perform.
When building a component library, I would evaluate the styling system as part of the architecture, alongside rendering strategy, design tokens, component composition, build tooling and long term maintainability.
Because the question is not simply how quickly we can write styles.
It is how efficiently we can generate, deliver and maintain them as the application grows.
If you were starting a large React application or a shared component library today, would you choose CSS Modules, Panda CSS or StyleX? What would influence your decision?