Installation
Install the Package
Configure Babel
Add the CSSX preset to your babel.config.js:
The default options work for most projects. See Babel Options for advanced configuration.
Verify Installation
Create a simple component to verify everything works:
Run your app and you should see the styled component.
Separate Style Files (Optional)
While inline styl blocks are recommended (easier composition, colocation with components), you can also use separate style files.
Files must be named with the .cssx.styl extension:
Import styles in your component:
Metro Config for Hot Reloading (Optional)
If you want .cssx.styl files to hot-reload during development, add the Metro config:
With an existing Metro config:
Note: Metro config is only needed for hot-reloading separate
.cssx.stylfiles. Inlinestylblocks work without it.
Web Support
CSSX is designed primarily for React Native and Expo projects. On web, it works seamlessly through react-native-web — if you're using Expo, web support is included automatically.
Pure React Web Projects
You can also use CSSX in pure React web projects (without React Native). Just add the Babel preset as shown above. If you use separate .cssx.styl files, configure your bundler (webpack, Vite, etc.) to watch for changes in those files for hot reloading.
TypeScript Support
CSSX is written in JavaScript but works seamlessly with TypeScript. The styl and pug template literals are typed to accept template strings.
For better IDE support with Stylus syntax, consider installing the Stylus language extension for your editor.
Next Steps
- Basic Usage - Learn how to use
stylandstyleName - Component Parts - Style child component parts
- CSS Variables - Dynamic theming support