Introduction
CSSX is a CSS-in-JS library that lets you write actual CSS syntax directly inside your JavaScript/TypeScript files. Unlike other CSS-in-JS solutions that use JavaScript objects to represent styles, CSSX uses real CSS — either plain CSS or Stylus syntax — giving you the full power of CSS with all its familiar syntax.
Why CSSX?
The Problem
Most CSS-in-JS libraries force you to write styles as JavaScript objects:
This has several drawbacks:
- Unfamiliar syntax (camelCase, no units, no shorthands)
- No CSS features like nesting, mixins, or variables
- Hard to copy styles from CSS references or design tools
- Different mental model from web CSS
The Solution
With CSSX, you write real CSS:
You can also use plain CSS if you prefer:
Key Features
True CSS Syntax
Write CSS the way it was meant to be written. Choose between:
styl- Stylus syntax with mixins, variables, and optional braces/semicolonscss- Plain CSS syntax for familiarity or easier migration
Both support all standard CSS properties and var() variables.
Cross-Platform
Works seamlessly on both React Native and Web (via react-native-web):
- Write once, run everywhere
- Same styles work on iOS, Android, and Web
- No platform-specific style files needed
Component Composition with :part()
Style internal parts of child components from the parent — similar to CSS Shadow Parts:
Dynamic CSS Variables
Use CSS var() syntax with runtime updates:
Material Design Grid
Built-in u unit (1u = 8px) for consistent spacing:
Performance Optimized
Automatic style caching prevents unnecessary re-renders. With the optional teamplay integration, styles are memoized and only recalculated when dependencies change.
How It Works
- Build Time: Babel transforms
styltemplate literals into optimized style objects - Runtime: The
styleNameprop applies matching styles based on class names - Parts: Components expose styled parts that parents can override
Use the part attribute to mark elements that can be styled from outside. The special part="root" maps to the standard style prop, letting parent components style your component directly:
Next Steps
- Installation - Set up CSSX in your project
- Basic Usage - Learn the core concepts
- Component Parts - Style component internals
- CSS Variables - Dynamic theming