Open the devtools on almost any Meta property and the markup looks like something went badly wrong. Every element carries a pile of classes like x1i10hfl, x1qhh985, xdj266r, and none of them mean anything to a human. For years the popular reading was that Facebook ships obfuscated Tailwind. It does not. Those classes are the compiled output of StyleX, and the more time you spend with it, the more the strategy makes sense.

StyleX has been public since 2023 and it mostly sat in the "interesting, not for me" pile. That changed recently, and not because the library got prettier. It got a new and unusually persuasive user: the coding agent sitting in your editor. Teams are moving to StyleX now because a rigid, typed, compiler-checked styling system is exactly what an LLM needs, and exactly what a human writing CSS by hand tends to resent.

What is StyleX and how does it actually work

StyleX is a compile-time CSS-in-JS library. You declare styles in a JavaScript object through stylex.create, and a compiler plugin turns those declarations into a static CSS file plus a set of class names during the build. The official plugin is built on Babel, and the SWC plugin you will find in many Next.js setups comes from the community, not from Meta. Nothing computes styles while your component renders. The docs are careful here and so should you be: there is no runtime style injection, but there is a tiny runtime whose only job is merging class names.

A minimal example looks like this.

import * as stylex from "@stylexjs/stylex";

const styles = stylex.create({
  panel: {
    display: "flex",
    flexDirection: "column",
    gap: 16,
    padding: 16,
    borderRadius: 12,
    backgroundColor: "white",
  },
});

Applying it means spreading stylex.props onto the element, because the function returns both className and, when dynamic styles are involved, a style object.

function Panel({ children }) {
  return <div {...stylex.props(styles.panel)}>{children}</div>;
}

The two features that carry the whole design are conditions and merging. States and breakpoints are not string prefixes, they are objects nested on the value of a property, with a default key and one key per condition.

const styles = stylex.create({
  cta: {
    color: "white",
    backgroundColor: {
      default: "#2563eb",
      ":hover": "#1d4ed8",
      ":active": "#1e40af",
    },
    width: {
      default: 480,
      "@media (max-width: 768px)": "100%",
    },
  },
});

Merging is where StyleX stops being a syntax preference and starts being an architecture. You pass several style objects into stylex.props and the last one that sets a property wins. Always. There is no specificity, no cascade, no source order in a stylesheet you have to reason about.

function Panel({ isHighlighted, style }) {
  return (
    <div
      {...stylex.props(
        styles.panel,
        isHighlighted && styles.highlighted,
        style,
      )}
    />
  );
}

Falsy values are ignored, so isHighlighted && styles.highlighted is idiomatic rather than a hack. Styles passed in from a parent are applied last by convention, which gives you a component that is open for extension without inventing a variants API for it.

Why does StyleX generate those unreadable class names

This is the part that separates StyleX from Svelte scoped styles, CSS modules, and the old styled-components Babel plugin. All of those generate a hashed class too, but they generate one hashed class per rule block. A card with a border, a background, a radius and a shadow becomes one class holding four declarations.

StyleX generates one class per unique property and value pair. padding-top: 0 is one class, globally, for the entire application. Use it in three components or in three hundred thousand, and the stylesheet still contains it once. That is why a single Facebook element carries thirty classes: each one is a single declaration.

The tradeoff is obvious in the markup and invisible in the network tab. Your HTML gets noisier, your CSS stops growing. The library's own pitch is that CSS size plateaus as the codebase grows, and that is the real claim worth testing. It is also why deterministic merging is possible at all. When every class holds exactly one declaration, "the last style wins" is something the library can guarantee by removing conflicting classes before the browser ever sees them, instead of hoping the cascade resolves the way you intended.

StyleX vs Tailwind: What the same component looks like

Here is a small card in Tailwind, with a hover state, a breakpoint, a conditional variant, and an escape hatch for the caller.

function ReleaseCard({ isBreaking, className }) {
  return (
    <article
      className={cn(
        "flex w-[480px] flex-col gap-4 rounded-xl bg-white p-4 max-md:w-full",
        isBreaking && "bg-amber-50 ring-2 ring-amber-400",
        className,
      )}
    >
      <h2 className="text-xl font-semibold text-slate-900">Release 4.2</h2>
      <button className="rounded-lg bg-blue-600 px-4 py-2 text-white hover:bg-blue-700">
        View changelog
      </button>
    </article>
  );
}

The same thing in StyleX.

import * as stylex from "@stylexjs/stylex";

const styles = stylex.create({
  card: {
    display: "flex",
    flexDirection: "column",
    gap: 16,
    padding: 16,
    borderRadius: 12,
    backgroundColor: "white",
    width: { default: 480, "@media (max-width: 767px)": "100%" },
  },
  breaking: {
    backgroundColor: "#fffbeb",
    boxShadow: "0 0 0 2px #fbbf24",
  },
  heading: { fontSize: 20, lineHeight: 1.4, fontWeight: 600, color: "#0f172a" },
  button: {
    paddingInline: 16,
    paddingBlock: 8,
    borderRadius: 8,
    color: "white",
    backgroundColor: { default: "#2563eb", ":hover": "#1d4ed8" },
  },
});

function ReleaseCard({ isBreaking, style }) {
  return (
    <article {...stylex.props(styles.card, isBreaking && styles.breaking, style)}>
      <h2 {...stylex.props(styles.heading)}>Release 4.2</h2>
      <button {...stylex.props(styles.button)}>View changelog</button>
    </article>
  );
}
Tailwind class strings versus StyleX style objects, and what each one does with a typo

Count the lines and Tailwind wins by a mile. Count the failure modes and the picture inverts. In the Tailwind version, bg-amber-50 and bg-white both end up in the class string and you are trusting cn to sort out which one applies. With tailwind-merge behind it, it will, but only because a runtime library knows every utility group and strips the loser for you. Write bg-amebr-50 and nothing happens, silently, in production, unless a Tailwind lint plugin happens to run in your editor and CI. Pass a className from a parent and whether it overrides anything depends on merge order and on whether the two utilities happen to target the same property. In the StyleX version, a misspelled style key is a type error, a misspelled property or value is a lint error, and the override question has one answer that never changes.

Why is StyleX better for AI agents than Tailwind

Tailwind became the default styling language for LLMs for a good reason. It is colocated, so a model reading a component sees both the structure and the appearance in one place, without following an import into a stylesheet it did not load. Models also had enormous amounts of Tailwind in their training data. Both of those things are still true.

What changed is that we now judge a styling system by what happens after a thousand agent edits, not after one. And that is where Tailwind's string-based nature costs you. A class name is just a string, so an agent can invent one. It can write text-balance-pretty because something like it existed in its training data, and your build will happily produce a page where that class does nothing. It can add p-4 to an element that already has px-6, and now the outcome depends on merge order. It can hardcode #3b82f6 instead of your token because nothing stops it. None of these produce an error by default. They produce drift, and drift is invisible until a designer notices that the same button has four shades of blue.

StyleX catches most of those before they ship, but not all of them in the same place, and the difference matters. Styles live in a typed namespace, so styles.buton fails to typecheck. Properties and values are not typed as strictly as you might expect: the TypeScript signature of create accepts any key, and most values are plain strings. The check that rejects a made-up property or a broken value is the valid-styles rule in @stylexjs/eslint-plugin, so if agents write your styles, that plugin is not optional. Tokens are the weak spot. A raw #3b82f6 inside create is perfectly legal, and no rule in the official plugin forbids it. What StyleX gives you instead is one statically known place where tokens live, which makes an off-token value easy to spot in a diff and easy to ban with a small custom lint rule.

// tokens.stylex.js
import * as stylex from "@stylexjs/stylex";

export const colors = stylex.defineVars({
  accent: "#2563eb",
  surface: "#ffffff",
  primaryText: "#0f172a",
});

That file extension is not decoration. Variables must live in a file ending in .stylex.js, .stylex.ts or a sibling extension, and every defineVars or defineConsts call must be a named export. The compiler needs to statically find them, and the constraint is the point: your design tokens have one obvious home, and a second one shows up in review as a new .stylex.ts file instead of hiding inside a component.

The honest summary is that Tailwind optimizes for the model's ability to produce plausible styling quickly, and StyleX optimizes for the toolchain's ability to reject wrong styling instantly. When a human wrote every line, the first mattered more. When a machine writes most of them and a human reviews a diff, the second does.

Does StyleX actually make pages faster

Sometimes, and less dramatically than the migration posts suggest. There are two real effects worth understanding, separate from any specific benchmark.

The first is stylesheet size. Atomic output deduplicates every declaration across your whole application, so the CSS you ship is bounded by the number of distinct declarations rather than by the number of components. Gzip already handles repeated strings well, which is the usual objection, but gzip does not remove the parsing work. The browser still constructs a rule for every duplicate declaration in the file before it can match anything.

The second is style resolution. Every class StyleX emits holds a single declaration, and conflicting classes are removed at merge time, so an element never carries two rules fighting over the same property. The browser still matches selectors and still runs the cascade, and StyleX still relies on rule order and specificity to rank pseudo classes and media queries, so this is less work, not no work. On a heavy page with deep component trees the difference can be measurable, and that is exactly the kind of claim worth profiling instead of trusting.

You will find migration posts promising a stylesheet cut in half and faster paint metrics. Treat those as directional at best. They came from someone else's page with someone else's component tree, and the only number that means anything for your app is the one you measure yourself before and after. If your CSS is 40 KB and your bottleneck is a 900 KB JavaScript bundle, styling is not what is slowing you down.

What does StyleX cost you

Writing it by hand is genuinely unpleasant, and pretending otherwise does nobody a favor. Compare var(--accent) in a stylesheet with the equivalent ceremony in a typed object graph, and CSS wins on ergonomics every time. Media queries and pseudo classes as nested condition objects are precise, verbose, and hard to skim.

The bigger structural cost is nesting, or rather the absence of it. In CSS you can style a span inside a heading with one nested selector, because you know that span exists only there. StyleX does not let a parent reach into its children, so every element gets its own entry in create and its own stylex.props call. Recent versions soften this with stylex.when.ancestor, stylex.when.descendant and the sibling variants, which let an element react to the state of a marked ancestor, descendant or sibling, such as a label that changes color when its card is hovered. The direction never flips, though: the styles still sit on the element being styled, not on its parent. If your styling instincts lean on structural selectors, you will feel this on every component.

Third, the escape hatch is real but blunt. Cutting-edge CSS that does not map to a property and value pair, or anything genuinely exotic, is easier to write in a plain stylesheet next to the component. That is fine and it is what most people do with Tailwind too. It stops being fine when half the codebase quietly lives in the escape hatch.

How to try StyleX without rewriting your app

Migrating everything is the wrong first move. A component library is the right one, because that is where consistency pays and where you write styles once and consume them everywhere.

  1. Add @stylexjs/stylex together with @stylexjs/eslint-plugin, wire the compiler into your build (the official Babel plugin, @stylexjs/unplugin for Vite and friends, or the community SWC plugin), then confirm a static CSS file is emitted and the linter runs in CI.
  2. Create a single tokens.stylex.ts with your colors, spacing and typography as defineVars, exported as named exports.
  3. Port two or three leaf components that many pages use, such as a button, a badge and a card.
  4. Give every ported component a style prop and apply it last in stylex.props, so callers can extend without forking the component.
  5. Measure your stylesheet size and one paint metric before and after, on a real page, so the decision rests on your numbers.
  6. Write the rule down for your agent, in AGENTS.md or the equivalent: new components use StyleX and tokens, no raw hex values, no new stylesheet.
  7. Only then decide whether the rest of the app follows.

Step six matters more than it looks. The whole argument for StyleX is that the machine has far fewer ways to go off-piste, and the ones that remain, raw values above all, only close when the machine is told which path it is on.

StyleX vs Panda CSS vs CSS modules: Which should you pick

Panda CSS deserves a serious look before you commit. It shares the compile-time atomic approach and the object syntax, and it has offered an opt-in tagged template mode that reads much closer to real CSS, so check the docs for the version you install before you plan around it. The bigger difference is nesting. Panda accepts native nesting with &, including descendant selectors like & span, which it discourages but does not block. If your objection to StyleX is ergonomics rather than architecture, Panda hands you most of the benefits without the daily friction. The price is that the same freedom is available to your agent, so the rule about which selectors are allowed lives in your conventions instead of in the compiler.

CSS modules remain a strong, boring answer for a codebase where humans still write most of the styles. You get scoping, you get real CSS with real nesting, and with editor auto-import you get the click-through-to-definition behavior that makes a component readable. What you do not get out of the box is a typed namespace that stops an agent from referencing a class that does not exist.

The choice comes down to who writes most of your styles next year. If it is people who know your design system, optimize for authoring pleasure and pick CSS modules or Panda. If it is agents producing volume that a human only reviews, optimize for what the toolchain can prove, and StyleX is the strongest answer currently shipping.

FAQ

Is StyleX better than Tailwind in 2026

For hand-written code, Tailwind is still faster to write and easier to skim. For codebases where agents produce most of the styling and a design system has to hold, StyleX is stronger because misspelled style names become type errors, invalid properties and values become lint errors, and tokens have exactly one place to live. Off-token raw values still need a rule of your own.

Does StyleX work without React

Mostly. StyleX is a compiler plus a small class name merging helper, so it works anywhere you write markup in JavaScript, although the docs say plainly that it is tuned for React today. stylex.props returns className and a style object, which is what React expects. For frameworks that want a class attribute and a style string, such as Vue, Svelte or plain HTML templates, use stylex.attrs instead.

Does StyleX have a runtime cost

There is no runtime style injection, since the CSS is generated at build time. There is a small runtime that merges class names when you combine style objects or use dynamic styles. That is a different and much cheaper thing than the old CSS-in-JS libraries that recomputed styles on every render.

Can you use StyleX and Tailwind in the same project

Technically yes, since both end up as plain classes. In practice it defeats the purpose. The value of StyleX is that one system owns every declaration, and the moment a Tailwind utility can override a StyleX class from outside, the deterministic merging guarantee is gone.

Why does Facebook use random CSS class names

Because those classes are compiler output, not something anyone wrote. Each one encodes a single property and value pair, which lets the entire application share one class per declaration and keeps the shipped stylesheet from growing with the codebase.

Happy styling!