Toolvito

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

Your values

Rules with a class, an id or an element name (.title { ... }), or only declarations (color: red; margin: 4px;).

Used only when you paste declarations without a selector and braces.

More options

1rem is this many px. Browsers use 16 unless the page changes it.

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.

How to use the style converter

  1. Paste CSS rules such as .title { font-size: 18px; color: #333; }, or only declarations such as color: red; margin: 4px;.
  2. Choose how to write the result: StyleSheet.create, a plain object or JSON.
  3. 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-top is marginTop.
  • 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. rem is multiplied by the root font size (16 unless you change it), pt by 4/3. A percentage stays a string such as '50%' where React Native takes one, and so does auto. em, vw, vh and calc() 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() and currentColor are refused.
  • Keywords must be ones React Native takes: display is only flex or none, position only absolute or relative. font-weight becomes a string such as '700'.
  • Shorthands are written out only into keys that exist: margin: 4px 8px becomes marginVertical: 4 and marginHorizontal: 8; border: 1px solid red becomes borderWidth, borderStyle and borderColor; transform becomes a list such as [{ rotate: '15deg' }, { scale: 1.1 }].
  • !important is 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, filter and outline exist 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.

Related tools