StyleX v0.13.0 introduces two new APIs and several breaking changes to compiler defaults, alongside various bug fixes.
New APIs
defineConsts
We've added a new defineConsts API to allow for declaration and use of constant values. Unlike defineVars, these are inlined at build-time and do not generate CSS variables. This is a long requested feature that allows for shareable media queries.
constants.stylex.js
export const breakpoints = stylex.defineConsts({
small: '@media (max-width: 600px)',
medium: '@media (min-width: 601px) and (max-width: 1024px)',
large: '@media (min-width: 1025px)',
});
export const colors = stylex.defineConsts({
brand: '#0055FF',
surface: '#FFFFFF',
text: '#111111',
});
You can then import and use these constants in any create call:
import * as stylex from '@stylexjs/stylex';
import { breakpoints, colors } from './constants.stylex.js';
const styles = stylex.create({
container: {
padding: {
default: '4px'
[breakpoints.small]: '8px',
[breakpoints.medium]: '16px',
[breakpoints.large]: '24px',
},
},
label: {
color: colors.text,
},
});
positionTry
positionTry enables graceful fallback positioning via the @property-try at-rule. This makes it easier to handle layout edge cases across varying browser support and runtime constraints. (Thanks nmn!)
const fallback = stylex.positionTry({
positionAnchor: '--anchor',
top: '0',
left: '0',
width: '100px',
height: '100px',
});
const styles = stylex.create({
box: {
positionTryFallbacks: fallback,
},
});
Breaking changes
- The
attrsAPI is removed due to low usage and redundant functionality; non-React users can replace it with a wrapper aroundpropsas documented here. - The
runtimeInjectioncompiler option is now disabled by default in development mode (dev:true) to better match production behavior. - ESLint rule
no-legacy-conditional-stylesis renamed tono-legacy-contextual-styles. - The config option
useRemForFontSizeis renamed toenableFontSizePxToRem; now disabled by default and not intended for external use. - The config option
genConditionalClassesis renamed toenableInlinedConditionalMerge; now enabled by default and not intended for external use.
Fixes
- Fixed duplicate classNames in styles with nested pseudo-classes (Thanks jeongminsang!)
- ESLint plugin now correctly supports
importSourcesobject syntax invalidImports(Thanks javascripter!) - Fixed a bug where CSS variables would be wrapped in quotes when used with the
contentproperty. - Fixed evaluation bug in
firstThatWorkswhen the final value was a CSS variable. - Fixed TypeScript types for themes and types functions.
Miscellaneous
- Rewrote the runtime style injection system to be more robust in dev. This resolves issues with hot reloading and duplicate style tags.
- Added Flow types for anchor positioning. (Thanks Jta26!)
- Added support for custom
importSourcesin the PostCSS plugin for React Strict DOM compatibility. (Thanks javascripter!) - Improved compiler error messages.
Deprecations
We’ve deprecated the @stylexjs/shared package on npm.

