talira

The expressive, type-safe, composable, predictable and themeable styling system for ambitious interfaces

open sourceMITself-hostablefree

StyleX is Meta's JavaScript syntax and compiler for styling web apps: you define styles as objects with stylex.create() next to your components and apply them with stylex.props(), and at compile time it turns them into a static file of collision-free atomic CSS, whose size levels off as the codebase grows, leaving only a tiny runtime that merges class names. The last style applied wins for each property, so styles compose predictably without specificity fights, and every style is typed, so components can declare which styles they accept. Variables, themes, light and dark modes, keyframes and view transitions are defined with defineVars, createTheme and related APIs. It works with Next.js, Vite, webpack, Rspack, esbuild, PostCSS and a CLI, mostly with React, and is MIT-licensed.

Problems it solves

  • our CSS bundle keeps growing with every feature and nobody dares delete old styles
  • styles from different components override each other unpredictably because of specificity
  • type-check which styles a React component accepts as props
  • write styles in JavaScript next to components but ship a static CSS file with no runtime style engine
  • define themes and design token variables that can be overridden for part of the page
  • merge and conditionally apply styles with plain JavaScript expressions and know which one wins
  • atomic CSS without memorising utility class names
  • lint our styling code for invalid properties and values

Features

  • stylex.create and stylex.props: object styles defined next to components
  • compile-time generation of a static, collision-free atomic CSS file
  • last applied style wins for each property; arbitrary styles merge and compose
  • typed styles: components can accept or restrict style props (StyleXStyles, StyleXStylesWithout)
  • variables, constants and themes with defineVars, defineConsts and createTheme
  • light and dark themes, context-driven styles with stylex.when
  • keyframes, view transition classes and position-try fallbacks
  • Babel plugin, PostCSS plugin, unplugin (Vite, webpack, Rspack, esbuild) and a CLI
  • ESLint plugin

Capabilities

Has a command line toolplan not known

Alternatives

The same job

These do what StyleX does.

  1. styled-components Fast, expressive styling for React. Server components, client components, streaming SSR, React Native, all one API.
  2. Emotion CSS-in-JS library designed for high performance style composition
  3. Panda CSS Universal, type-safe, CSS-in-JS framework for design systems
  4. vanilla-extract Zero-runtime Stylesheets-in-TypeScript
  5. Tailwind CSS Rapidly build modern websites without ever leaving your HTML.
  6. goober A less than 1KB css-in-js solution

Compare StyleX with the top 3