Works on this device
React Native Style Converter
Paste CSS and get React Native styles for StyleSheet.create, a plain object or JSON. Property names become camelCase, px values become numbers, shorthands are written out into the keys React Native has, and every declaration React Native does not support is listed with the reason. The code is only written as text; nothing is run.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose Convert.
Your result
How it was worked out
How to use the style converter
- Paste CSS rules such as
.title { font-size: 18px; color: #333; }, or only declarations such ascolor: red; margin: 4px;. - Choose how to write the result:
StyleSheet.create, a plain object or JSON. - Copy the code. Read the table of refused declarations: those need another way in React Native.
The conversion rules
- Each rule with a single class (
.card-title), id (#main) or element name becomes a style, named in camelCase (cardTitle). Rules with other selectors (.list > li,:hover) are refused, because React Native has no selectors. - Property names are written in camelCase:
margin-topismarginTop. - A length in px becomes a plain number, because React Native counts in density-independent pixels (dp); one CSS px is taken as one dp.
remis multiplied by the root font size (16 unless you change it),ptby 4/3. A percentage stays a string such as'50%'where React Native takes one, and so doesauto.em,vw,vhandcalc()are refused. - A line height without a unit (such as 1.5) is multiplied by the font size of the same rule: React Native needs line height in dp.
- Colours stay as written in hex,
rgb(),rgba(),hsl(),hsla()or a colour name.lab(),lch(),oklch()andcurrentColorare refused. - Keywords must be ones React Native takes:
displayis onlyflexornone,positiononlyabsoluteorrelative.font-weightbecomes a string such as'700'. - Shorthands are written out only into keys that exist:
margin: 4px 8pxbecomesmarginVertical: 4andmarginHorizontal: 8;border: 1px solid redbecomesborderWidth,borderStyleandborderColor;transformbecomes a list such as[{ rotate: '15deg' }, { scale: 1.1 }]. !importantis dropped, because React Native has no cascade. When a style gets the same key twice, the later value wins.
Worked example
In the example, .card-title has font-size: 18px, line-height: 1.5 and letter-spacing: 0.05rem. It becomes cardTitle with fontSize: 18, lineHeight: 27 (1.5 × 18) and letterSpacing: 0.8 (0.05 × 16). padding: 12px 16px becomes paddingVertical: 12, paddingHorizontal: 16.
box-shadow and float are refused: React Native has its own shadow keys that differ by platform, and no float.
Limits you should know
- The list of supported properties follows the React Native style documentation (View, Text, Image, layout and transform props). Newer properties such as
boxShadow,filterandoutlineexist only in recent versions and are not converted. Check the documentation of your React Native version. - Media queries, hover and focus states, animations, grid layout, background images and gradients have no direct React Native style and are refused.
- One CSS px is not always one dp on screen: the device decides the size of a dp. The numbers keep the sizes of the design.
- Converting React JavaScript files to TypeScript is not done here.