CSS to JS Object screenshot

CSS to JS Object

Turn CSS rules into a JavaScript object keyed by selector: declarations as string values, optional camelCase keys, at-rules refused by name.

Privacy First
0 Runs
Updated 2026-11-17
Runs in your browser
No sign-up, no upload

What the CSS to JS Object does

Every block is parsed into a selector and a list of declaration pairs, so a value containing a colon or a semicolon — a URL, a custom property, a quoted font name — stays in one piece.

Values are not normalised: 8px 16px stays two lengths, and a custom property keeps its -- name. The object is a faithful copy of the rule's declarations.

At-rules are refused by name. Flattening @media into one object would lose the condition under which its declarations apply, and a nested object would no longer be the shape a CSS-in-JS library reads. Nested selectors (&:hover) are refused for the same reason.

How to use it

Paste the rules into the CSS box, or press Run with the example already there.

Read the JS object below: one key per selector, and inside it one key per declaration.

Set camelCase keys to yes and press Run for a new JS object when your library wants paddingTop instead of padding-top.

Worked example

Input:

.card { color: #fff; padding: 8px 16px; }

Output:

{
  ".card": {
    "color": "#fff",
    "padding": "8px 16px"
  }
}

Why it runs in your browser

The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.

The object a CSS-in-JS library or a test fixture wants: one key per selector, one key per declaration, values kept as the exact strings you wrote.

Keys are quoted CSS properties by default; set camelCase keys to `yes` when your library expects `backgroundColor` rather than `background-color`.

What it does, and what it does not

Every block is parsed into a selector and a list of declaration pairs, so a value containing a colon or a semicolon — a URL, a custom property, a quoted font name — stays in one piece.

Values are not normalised: `8px 16px` stays two lengths, and a custom property keeps its `--` name. The object is a faithful copy of the rule's declarations.

At-rules are refused by name. Flattening `@media` into one object would lose the condition under which its declarations apply, and a nested object would no longer be the shape a CSS-in-JS library reads. Nested selectors (`&:hover`) are refused for the same reason.

How to use CSS to JS Object

Paste the rules into the CSS box, or press Run with the example already there.

Read the JS object below: one key per selector, and inside it one key per declaration.

Set camelCase keys to yes and press Run for a new JS object when your library wants `paddingTop` instead of `padding-top`.

What to Expect

Best for

  • Moving a rule into a CSS-in-JS object
  • Building a small fixture for a style test

Not ideal for

  • A stylesheet with media queries, which are refused
  • Nested selectors, which need a different shape

What this tool keeps

  • Declaration order within a rule
  • Values byte for byte, including shorthands

What may need cleanup

  • Split a shorthand yourself if the library wants longhands
  • Flatten a media query by hand

Common errors

  • The page refuses it: is an at-rule; a plain object cannot hold its condition

Example use cases

  • Porting a component rule into a JS theme object
  • Asserting a rule's declarations in a test

Sample input

CSS: .card { color: #fff; padding: 8px 16px; }

Sample output

JS object: { …

Who this is for

  • React developers using a CSS-in-JS library
  • Anyone whose test asserts computed declarations

Frequently asked questions

Why are values strings?

A declaration's value is not always a number, and converting 8px to 8 silently changes its meaning. The object keeps the authored string, which every CSS-in-JS library accepts.

Why refuse an at-rule?

A media query is a condition, not a selector. Folding its declarations into one object would make them look unconditional, so the page refuses and names the at-rule.

Does camelCase change the values?

No. Only the property keys change — background-color becomes backgroundColor — and values keep the exact text you wrote, including vendor prefixes.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.