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.
Configure ESLint
If your project uses Pug templates, install ESLint v9 and the CSSX ESLint plugin:
Use ESLint v9 with the flat config format. Do not use eslint@latest if it resolves to ESLint v10.
With neostandard:
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 works with TypeScript. If your project uses Pug templates, run Pug-aware type checks with npx cssxjs check instead of relying on tsc --noEmit alone.
See TypeScript Support for details.
VS Code Extension
Install the following extension for full CSSX support with Pug and CSS/Stylus in style or style(lang='styl') tags:
For support of the Stylus syntax itself, install the Stylus language extension.
Next Steps
- Basic Usage - Learn how to use
stylandstyleName - TypeScript Support - Type-check Pug templates
- Component Parts - Style child component parts
- CSS Variables - Dynamic theming support