Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Meta Engineering 10 min read Deep dive mediumAdept

StyleX: A Styling Library for CSS at Scale

StyleX is Meta's build-time CSS-in-JS compiler that extracts style objects into collision-free atomic CSS, replacing the earlier cx system and cutting CSS size by 80% across Facebook, Instagram, WhatsApp and others. A Babel plugin hashes each property-value pair into a class, caches per file, and uses deterministic hashes for defineVars/defineConsts so it never reads imported modules. Merging is predictable (last style wins), and shorthand/longhand, pseudo-class and media-query conflicts are resolved by computing numeric priorities enforced via @layer or a polyfill. Constraints such as banning global and descendant selectors prevent styling at a distance, while stylex.when, dynamic styles via CSS variables, and theming APIs keep it expressive.

Related posts

  • Styling Linear for the future with StyleX

    Linear mediumAdept

    Linear migrated its React apps from styled-components to Meta's StyleX over more than 1,000 PRs. It moved style generation to build time and made styling contracts between components explicit and enforced. The work combined a deterministic codemod, narrowly scoped coding agents and manual review, starting with leaf components while both systems coexisted. Oxlint rules and a type-aware cross-file checker enforce `sx` prop propagation, merge precedence and design tokens, with CSS Modules kept as an escape hatch. Runtime-generated LCH themes were kept by injecting StyleX's hashed variable names per ThemeProvider, and removing runtime style injection cut main-thread CPU work by roughly 20–35% on view-heavy pages.

  • Improving site performance by shipping more CSS

    GitHub Engineering mediumAdept

    GitHub migrated its Primer Design System and the github.com codebase from styled-components CSS-in-JS to CSS Modules, removing runtime styling costs on client and server. Primer components moved first, each behind a feature flag and checked against visual regression snapshots, which cut server-side render time by 55% and component initialization by 25%. A wrapper package, @primer/styled-react, kept the legacy `sx` prop working during the transition. About 7,760 `sx` props were then migrated with a VS Code plugin, codemods and later Copilot coding agents, followed by decoupling theming, and dotcom reached 100% CSS Modules in June 2026 without breakage.

  • Hydrogen & Tailwind: The Perfect Match for Building Beautiful Storefronts

    Shopify Engineering mediumAdept

    Tailwind's utility classes ship as the default styling option in Shopify's React-based Hydrogen storefront framework, and the case for them rests on componentization: styles live in reusable React components rather than semantically named classes like BEM-style product-card__title, so layouts can be copied or extracted (e.g. ProductCard to BlogCard) without renaming or duplicating CSS. Further arguments include enforced spacing and color constraints for visual consistency, copy-paste composability from libraries like Tailwind UI, easier team collaboration, and not having to name things. The tradeoff is a real learning curve that still requires CSS fundamentals, eased by good docs and the VSCode extension.

  • Help choose the syntax for CSS Nesting

    WebKit mediumAdept

    The CSS Working Group is choosing between three candidate syntaxes for native CSS nesting, since Sass-style nesting is impossible: browser parsers would read a nested selector like `element:pseudo` as a `property: value` declaration. Option 3 lets nested rules sit directly in the declaration block but forbids them from starting with a letter, so element selectors need `&` or an `:is()` wrapper. Option 4 adds an optional second block after the declarations that holds only nested rules. Option 5 introduces a dedicated `@nest` at-rule. Side-by-side examples cover basics, nested nesting, media queries and cascade layers, and developers are asked to vote in a survey.

  • New to the web platform in August

    web.dev easyNovice

    Chrome 152 and Firefox 154 shipped to stable in August 2026, making several features Baseline Newly available: the text-box-trim/text-box-edge properties for trimming font leading, the sibling-count() and sibling-index() CSS functions, and the global autocorrect attribute. Chrome 152 also adds the CSS Color 5 alpha() function, the standardized window-drag property replacing app-region, OpaqueRange for range APIs over form-control text, and CSSPseudoElement support for ::backdrop, ::scroll-marker and ::view-transition. Firefox 154 adds Iterator helpers (includes, join, chunks, windows) and WebRTC transport APIs such as getSelectedCandidatePair(). The Chrome 153 and Firefox 155 betas preview single-axis scroll containers, Iterator zip, <camera>/<microphone> elements, and URL properties on SVG <a> elements.

The quest for software engineering knowledge.

Look:
Layout: