UTILS.
100% in-browser
💅

CSS to JS Style Object

Convert a block of CSS declarations into a JavaScript style object for React inline styles, styled-components, or Emotion, with camelCased properties.

— output appears here —

About this tool

The CSS to JS Style Object tool converts a block of CSS into a JavaScript object suitable for React inline styles or CSS-in-JS libraries like styled-components and Emotion. It parses the declarations locally in your browser — nothing is uploaded — so migrating a stylesheet to inline styles is a paste-and-copy away.

Each property name is camelCased: background-color becomes backgroundColor, z-index becomes zIndex. Vendor prefixes follow React's rules — a leading -ms- lowercases to ms (msFilter), while -webkit-, -moz-, and -o- capitalize to Webkit, Moz, and O (WebkitBoxShadow). Custom properties (--brand-color) are kept verbatim as quoted keys. Values are emitted as strings by default, preserving units and !important; a numeric toggle lets bare integers and decimals become unquoted numbers instead. Keys that are valid JavaScript identifiers are left unquoted; the rest are quoted automatically.

When the input is a plain declaration block (no selectors) it produces one flat object, perfect for a React style prop. When the input contains full rules with selectors, the styled/Emotion mode emits a nested object keyed by each selector string — the object syntax those libraries accept. You control the output const name, and the whole thing is written as const styles = { ... }; ready to paste.

Frequently asked questions

How are property names transformed?
Hyphenated properties are camelCased (background-color to backgroundColor). Vendor prefixes follow React: -ms- becomes a lowercase ms prefix, while -webkit-, -moz-, and -o- become Webkit, Moz, and O. Custom properties like --foo are kept as quoted keys.
Are values numbers or strings?
By default every value is a string, which is always safe and keeps units and !important intact. Enable the numeric toggle and purely numeric values (like z-index: 10) are emitted as unquoted numbers instead.
What is the difference between the two modes?
React inline mode emits a single flat object from a declaration block. Styled / Emotion mode emits a nested object keyed by selector strings, matching the object syntax styled-components and Emotion accept for multiple rules.
Does it handle full CSS rules with selectors?
Yes. If the input contains selectors and braces, each rule is parsed into its own nested object under the selector key. A bare declaration list with no selectors produces one flat style object.

More tools