Gathering detailed insights and metrics for css-to-react-native
Gathering detailed insights and metrics for css-to-react-native
Gathering detailed insights and metrics for css-to-react-native
Gathering detailed insights and metrics for css-to-react-native
taro-css-to-react-native
Convert CSS text to a React Native stylesheet object
css-to-react-native-transform
Convert CSS text to a React Native stylesheet object
@native-html/css-processor
An inline CSS processor to translate CSS properties to React Native styles.
@jsamr/react-native-li
A pure JavaScript React Native component to render CSS3 compliant ordered and unordered lists.
Convert CSS text to a React Native stylesheet object
npm install css-to-react-native
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
1,204,489,302
Last Day
1,184,162
Last Week
6,244,648
Last Month
26,828,473
Last Year
291,177,112
MIT License
1,154 Stars
202 Commits
82 Forks
38 Watchers
6 Branches
108 Contributors
Updated on May 03, 2025
Minified
Minified + Gzipped
Latest Version
3.2.0
Package Id
css-to-react-native@3.2.0
Unpacked Size
87.91 kB
Size
18.86 kB
File Count
44
NPM Version
9.1.1
Node Version
16.18.0
Published on
Feb 14, 2023
Cumulative downloads
Total Downloads
Last Day
50%
1,184,162
Compared to previous day
Last Week
4.8%
6,244,648
Compared to previous week
Last Month
-5.6%
26,828,473
Compared to previous month
Last Year
-3.2%
291,177,112
Compared to previous year
Converts CSS text to a React Native stylesheet object.
1font-size: 18px; 2line-height: 24px; 3color: red;
1{ 2 fontSize: 18, 3 lineHeight: 24, 4 color: 'red', 5}
Converts all number-like values to numbers, and string-like to strings.
Automatically converts indirect values to their React Native equivalents.
1text-shadow-offset: 10px 5px; 2font-variant: small-caps; 3transform: translate(10px, 5px) scale(5);
1{ 2 textShadowOffset: { width: 10, height: 5 }, 3 fontVariant: ['small-caps'], 4 // Fixes backwards transform order 5 transform: [ 6 { translateY: 5 }, 7 { translateX: 10 }, 8 { scale: 5 }, 9 ] 10}
Also allows shorthand values.
1font: bold 14px/16px "Helvetica"; 2margin: 5px 7px 2px;
1{ 2 fontFamily: 'Helvetica', 3 fontSize: 14, 4 fontWeight: 'bold', 5 fontStyle: 'normal', 6 fontVariant: [], 7 lineHeight: 16, 8 marginTop: 5, 9 marginRight: 7, 10 marginBottom: 2, 11 marginLeft: 7, 12}
Shorthands will only accept values that are supported in React, so background
will only accept a colour, backgroundColor
There is also support for the box-shadow
shorthand, and this converts into shadow-
properties. Note that these only work on iOS.
border{Top,Right,Bottom,Left}
shorthands are not supported, because borderStyle
cannot be applied to individual border sides.
The API is mostly for implementors. However, the main API may be useful for non-implementors. The main API is an array of [property, value]
tuples.
1import transform from 'css-to-react-native'; 2// or const transform = require('css-to-react-native').default; 3 4transform([ 5 ['font', 'bold 14px/16px "Helvetica"'], 6 ['margin', '5px 7px 2px'], 7 ['border-left-width', '5px'], 8]); // => { fontFamily: 'Helvetica', ... }
We don't provide a way to get these style tuples in this library, so you'll need to do that yourself. I expect most people will use postCSS or another CSS parser. You should try avoid getting these with string.split
, as that has a lot of edge cases (colons and semi-colons appearing in comments etc.)
For implementors, there is also a few extra APIs available.
These are for specific use-cases, and most people should just be using the API above.
1import { getPropertyName, getStylesForProperty } from 'css-to-react-native'; 2 3getPropertyName('border-width'); // => 'borderWidth' 4getStylesForProperty('borderWidth', '1px 0px 2px 0px'); // => { borderTopWidth: 1, ... }
Should you wish to opt-out of transforming certain shorthands, an array of property names in camelCase can be passed as a second argument to transform
.
1transform([['border-radius', '50px']], ['borderRadius']); 2// { borderRadius: 50 } rather than { borderTopLeft: ... }
This can also be done by passing a third argument, false
to getStylesForProperty
.
Licensed under the MIT License, Copyright © 2019 Krister Kari, Jacob Parker, and Maximilian Stoiber.
See LICENSE.md for more information.
No vulnerabilities found.
Reason
all changesets reviewed
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
48 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More