Free CSS to JavaScript Converter

Convert CSS properties to JavaScript style objects. Transform kebab-case properties to camelCase. Perfect for React and styled-components.

Output Format:
Example: background-color: #007bff;
padding: 10px 20px;
border-radius: 4px;
Converts to: { backgroundColor: '#007bff', padding: '10px 20px', borderRadius: '4px' }

How the Conversion Works

The transformation is a small set of mechanical rules applied per declaration. Property names: kebab-case → camelCase. background-color becomes backgroundColor, border-radius becomes borderRadius, margin-top becomes marginTop. Each hyphen is removed and the next letter is capitalised. Vendor prefixes follow the same rule with one famous exception: -webkit-transform becomes WebkitTransform (capital W), -moz-appearance becomes MozAppearance (capital M), but -ms-flex becomes msFlex with a lowercase m. This Microsoft-prefix exception is documented in the React DOM source and trips up almost every developer the first time they hit it. Values: stringify them. color: red becomes color: 'red'; border-radius: 4px becomes borderRadius: '4px'. The exceptions are unitless properties (z-index, opacity, line-height, flex-grow and a fixed list of others maintained by React DOM) where bare numbers are valid: z-index: 5 can become zIndex: 5 (number) or zIndex: '5' (string) and React will accept both. Important: !important annotations don't survive the conversion to React inline styles, React's style prop ignores !important. If you need !important, you need a real stylesheet, not inline styles. Quoting: string values with apostrophes need escaping; content: '' for the empty string requires double quotes around single quotes (content: "''").

The CSS-in-JS Movement, Briefly

Why does this conversion problem exist at all? Because in 2014 a generation of frontend developers decided that CSS in separate stylesheets had failed at scale. The founding moment was Christopher "Vjeux" Chedeau's talk "CSS in JS" at NationJS on 15 November 2014: a Facebook engineer arguing that CSS's global cascade, lack of dependency tracking, and dead-code accumulation made it the worst part of large web apps. The talk lit a movement. JSS (Oleg Slobodskoi) shipped in late 2014 as the first general-purpose CSS-in-JS library. CSS Modules arrived in 2015 as a build-time approach to scoping. styled-components (Glen Maddern + Max Stoiber) shipped in October 2016, popularising the tagged-template-literal API where you write CSS inside backticks attached to a component definition. Emotion (Kye Hohenberger) shipped on 10 July 2017 with both the styled-components style API and a more flexible css prop that took JavaScript objects directly, exactly the format this tool produces. Stitches (Modulz/Pedro Duarte) shipped in 2020 with a variant-based API but became unmaintained in mid-2023 and was formally archived in April 2026.

The pendulum has swung back. Sam Magura's "Why We're Breaking Up with CSS-in-JS" on 16 October 2022 (written by an Emotion maintainer) was the inflection point. The technical case: runtime CSS-in-JS measurably slows down React renders (Magura's own benchmark on the Spot Member Browser dropped median render time from 54.3 ms to 27.7 ms after migrating off Emotion, roughly 2× faster); bundle sizes are larger; serialisation costs accumulate. The architectural case: React Server Components (stabilised by Next.js 13.4 on 4 May 2023) cannot use React Context, which most CSS-in-JS libraries depend on for theming. The replacement wave: Tailwind CSS (Adam Wathan, with v4 launching 22 January 2025); Vanilla Extract (Mark Dalgleish at Seek, 26 March 2021) for build-time CSS-in-TypeScript; CSS Modules for scoped class names without runtime cost; and the surviving compile-to-static crop named in the Magura post itself: vanilla-extract, Linaria, Compiled, StyleX and Pigment CSS. JSS itself was deprecated on 14 May 2024; styled-components went into maintenance mode on 17 March 2025. Runtime CSS-in-JS is no longer the default for new React projects in 2026, but a gigantic codebase of existing styled-components and Emotion code persists, and converting CSS to those libraries' object form is still the daily reality for many teams.

The Major Libraries' API Surfaces

React inline style (the style prop) is the universal baseline, every React component accepts a style object whose keys are camelCase CSS properties. No support for pseudo-classes (:hover), media queries, or !important; this is "inline style" in the old HTML style="..." attribute sense, just with a JavaScript object instead of a string. The output of this tool drops directly into style={...}. styled-components takes tagged template literals containing real CSS strings: const Button = styled.div`background: red; padding: 10px;`. The CSS is real CSS, kebab-case and all, you usually don't need this converter for styled-components unless you're moving from inline styles to a styled component. Emotion supports both APIs: the styled API (template literals like styled-components) and the css prop with a JavaScript object (camelCase, exactly the format this tool produces). For Emotion's css prop, this converter's output is directly usable. JSS uses a similar object format with some additional features (theming, automatic generated class names) but the basic camelCase property syntax is the same. Vue's style binding (:style="...") accepts the same camelCase object syntax as React's inline style. Vanilla Extract uses a stricter typed object form with explicit style({ ... }) wrapper functions; the inner camelCase object is the same shape.

Edge Cases and Gotchas

Common Use Cases

Honest Scope: What This Tool Does and Doesn't

This tool converts CSS declarations to JavaScript object syntax with camelCase keys and correctly-quoted string values. It handles the vendor-prefix capitalisation rules (including the lowercase ms exception). It does not translate to a specific library's API beyond producing the camelCase object, you still have to know whether your codebase wants the object inside styled.div\`...\`, inside an Emotion css call, inside a React style prop, or inside a Vue :style binding. The choice depends on your library, not the converter. The tool also does not handle nested rules and pseudo-selectors automatically, Emotion's nested-object syntax ('&:hover': {...}) and styled-components' template-literal nesting work differently and need manual structuring. For a complete migration from a CSS file to a CSS-in-JS library, expect to do some restructuring beyond the property-by-property conversion this tool provides.

Privacy: Why Browser-Only Matters Here

CSS rarely contains secrets, but proprietary stylesheets reveal information about a site's internal class taxonomy, its design system tokens, and sometimes its A/B-test hypothesis through experiment-specific selectors. Server-side conversion tools require uploading the CSS, which sits in their logs. For internal product styles, design-system source-of-truth files, or work-in-progress branding, browser-only conversion keeps it local. This tool runs the entire transformation in your browser, verify in DevTools' Network tab while you click Convert, or take the page offline (airplane mode) and the converter still works.

Frequently Asked Questions

How are CSS properties converted to camelCase?

Each hyphen in a kebab-case CSS property is removed and the next letter is capitalised: background-colorbackgroundColor, border-radiusborderRadius, margin-topmarginTop. Vendor-prefixed properties follow the same rule with capitalisation: -webkit-transformWebkitTransform (capital W), -moz-appearanceMozAppearance. The famous exception is Microsoft's prefix: -ms-flexmsFlex with a lowercase m, because that's how React DOM defines it.

Does this work for media queries and pseudo-classes?

Plain JavaScript style objects (the React style prop, Vue :style) do not support media queries or pseudo-classes, those are stylesheet concepts. CSS-in-JS libraries that accept object syntax (Emotion's css prop, JSS) support them through nested objects: '&:hover': { background: 'red' }, '@media (min-width: 768px)': { padding: '20px' }. The destination library's documentation will show the exact nesting structure. This tool produces the flat object; you wrap it in the library's nesting syntax manually.

Why doesn't !important work in React inline styles?

The React style prop silently ignores !important annotations, they aren't part of the JS object literal grammar and React's renderer doesn't translate them. If you need to override a higher-specificity rule, use a real stylesheet (CSS Modules, Tailwind, styled-components, plain CSS). React's inline-style mechanism is for one-off or dynamic styles where specificity isn't a concern; !important belongs in a stylesheet.

Should I still be using CSS-in-JS in 2026?

For new React projects, the current default is "no, use Tailwind, CSS Modules, or Vanilla Extract." Sam Magura's October 2022 article from inside the Emotion team (combined with React Server Components' Context incompatibility) pushed the ecosystem toward build-time-only solutions. styled-components moved to maintenance mode on 17 March 2025; JSS was deprecated on 14 May 2024. For existing codebases with significant styled-components or Emotion investment, no rush to migrate, both libraries still work, and the runtime cost is the kind of thing you optimise when it shows up in profiling. For a brand-new project in 2026: Tailwind v4 (released 22 January 2025) is the most popular choice; Vanilla Extract for projects that want strict TypeScript typing on styles; CSS Modules for projects that want minimal abstraction.

Can I convert design-system tokens this way?

For a one-off snippet, yes. For an entire design system (typically dozens or hundreds of tokens organised by colour, spacing, typography, motion) use a dedicated tool like Style Dictionary or Theo, both of which take a single source of truth (JSON, YAML, or JS) and output to multiple destinations (CSS custom properties, JS constants, iOS Asset Catalogs, Android XML, etc.). The advantage of a real design-token tool is consistency across platforms; this converter is for the case where you have a CSS snippet in hand and want JS form right now.

Is my CSS sent anywhere?

No. The conversion runs entirely in your browser via JavaScript. The CSS you paste never crosses the network, verify in DevTools' Network tab while you click Convert, or take the page offline after it loads and confirm the tool still works. Safe for proprietary stylesheets, design-system source-of-truth files, or any CSS that reveals internal class taxonomies you wouldn't want copied onto a stranger's hard drive.

Related Tools