Web only features
Unistyles comes with some web-only features that are not available on the React Native side.
Web only styles
In Unistyles, you can use web-specific styles for your web app under the _web
key.
The _web
key supports any CSS property and value that matches the CSSProperties
type from React.
The transform
property on the web should be a string:
Or can be lifted to the style
level:
You can also use variants, breakpoints, and other Unistyles features under the _web
key!
Pseudo elements
Unistyles also introduces a way to use any pseudo-elements and selectors in your web styles.
As you can see, :
and ::
have been replaced with _
for easier usage.
Injecting custom classNames
If you want to write some part of your app with plain CSS, you can add custom classNames
to your styles:
The _classNames
key under the _web
key will be injected into the DOM element as a className
. You can pass a string or an array of strings into it:
You can also use some conditions while resolving your classes:
CSS Variables
Unistyles 3.0 converts all your themes to CSS variables by default, eliminating heavy JS processing when changing the theme and allowing the CSS engine to take over.
In more detail, it converts all strings into CSS variables. For example, if we have the following theme:
It will be converted to:
After conversion, Unistyles will use CSS variable instead of string to reference the theme value.
If you’re using adaptiveThemes
CSS variables will be placed under the @media (prefers-color-scheme)
query ensuring that the app will automatically switch to the new theme.
If you’re not using adaptiveThemes
Class of your html root element will be updated to match the new one.
When to disable CSS variables?
When you have different size variables / functions in your themes
When you use conditions to style your components instead of relying on the same theme values
If none of the above applies to you, you can use CSS variables to boost your app’s performance.