CSS Hooks
Documentation
Source on GitHub

CSS power.
Inline style simplicity.

The styling system that gives native inline styles pseudo-classes, media queries, container queries, feature queries, and selector logic.

Pseudo-classes
<button style={pipe( { background: "oklch(45.76% 0.18 265)", color: "white", }, on("&:hover", { background: "oklch(56.45% 0.18 265)", }), on("&:active", { background: "oklch(56.45% 0.19 25)", }) })} > Save changes </button>
Selectors
<label> <input type="checkbox" checked /> <span style={pipe( {}, on(":checked + &", { textDecoration: "line-through" }) )} > Simplify CSS architecture </span> </label>
Responsive design
<span style={pipe( {}, on(or("@container (width < 50px)", "@container (width >= 100px)"), { display: "none" }) )} > sm </span> <span style={pipe( {}, on("@container (width < 100px)", { display: "none" }) )} > lg </span>
smlg

Benefits


Expressive

Best of both worlds

Stop bouncing between files. Use pseudo-classes, selectors, and responsive queries directly within the style prop. You get the power of CSS where it makes the most sense—on the target element itself—without the className overhead.


Colocated

Local reasoning

Keep styles and markup in the same context. When components are self-contained, you stop hunting through external stylesheets to find a layout bug. You can refactor confidently, knowing your changes are scoped exactly where they're written.


Type-safe

Strictly typed styles

Catch errors in your editor, not the browser. Every property and value is fully typed, eliminating magic strings and non-standard shorthands. Because styles are just plain objects, your existing refactoring tools and type-checking work out of the box—no custom IDE plugins or complex configurations required.


Deterministic

No more cascade

Eliminate the complexities of specificity, source order, and cascade layers. By defining styles directly on the target element, you ensure that they render exactly as intended. Since the styling logic lives in your component rather than a complex global stylesheet, you can say goodbye to hydration mismatches and flashes of unstyled content.


Efficient

Static stability, dynamic delivery

This approach combines the modularity of runtime CSS-in-JS with the performance of static CSS. A tiny stylesheet added once at startup handles the plumbing, and CSS variable fallbacks handle the rest—ensuring that your styling payload stays proportional to your active UI instead of your entire application. All without the overhead of client-side style injection.


Packages

React

npm i @css-hooks/react

Preact

npm i @css-hooks/preact

Solid

npm i @css-hooks/solid

Qwik

npm i @css-hooks/qwik

Opinions

Mark Dalgleish
Mark Dalgleish
@markdalgleish

Check out CSS Hooks. This is *very* cool.

It lets you write type-safe inline styles (literally the `style`attribute *BUT* with support for a custom set of pseudo-classes, selectors, media/container queries — and nested too!

Ryan Florence
Ryan Florence
@ryanflorence

That's how I always wished the style prop worked!

Mykhaylo
Mykhaylo
@mryechkin

I absolutely love it. There's just something "fresh" about it. Simple to get started, practically no overhead, and it just makes sense. Best part is that it does this all using native CSS features, nothing fancy - just really cleverly done.

Nicolas
Nicolas
@nicolas_dev_

Looks exactly like what I always wanted the style property to be

Will be trying it out for sure!

Julien Delort
Julien Delort
@Julien_Delort

I was _hooked_ at "no build step"!

Benton Boychuk-Chorney
Benton Boychuk-Chorney
@b_e_n_t_e_n_

I'm curious if there is a "catch" to css hooks, because from first glance it seems too good to be true!