CSS Hooks
Documentation
Source on GitHub

FAQ

How does CSS Hooks work?

CSS Hooks renders a small stylesheet that tracks the declared selectors, at-rules, and flags. Declarations apply directly on an element through its style prop. Conditions are encoded in each value. The stylesheet activates conditions without requiring specialized rulesets per component.

Which rules belong in a stylesheet?

CSS Hooks works by filtering an element’s own style declarations with conditions. Some rules do not fit that model, such as @keyframes, pseudo-elements like ::before and ::after, and styling for markup you do not control. Prefer inline styles where possible. Otherwise, keep the rule in a stylesheet.

How can an ancestor apply styles to a descendant element?

Hooks do not allow an ancestor to style a descendant directly. Instead, a hook acts as a filter on declarations, activating when the element to which they apply matches the hook’s logic. Such logic can include contextual selectors, so you can style a descendant based on its position within a group:

typescript
// The child changes when an ancestor with class="group" is hovered. on(".group:hover &", { color: "rebeccapurple", })

Use Flags to share state with descendants. Each descendant defines its own styles for that state.

For cases where you do not control the descendant markup, a traditional stylesheet may be the appropriate tool.

Why don’t hooks support pseudo-elements?

Pseudo-elements target virtual elements rather than the existing element that owns a style object. Use a physical element when possible, or keep the pseudo-element rule in a stylesheet.

Note Some common use cases for pseudo-elements can be solved with physical elements instead. For example, a physical placeholder element’s visibility can be controlled using the :placeholder-shown pseudo-class, as demonstrated in the Floating label recipe.

Is CSS Hooks widely supported in browsers?

CSS Hooks supports the following browser versions:

Chrome
Chrome
Edge
Edge
Safari
Safari
Firefox
Firefox
Opera
Opera
118+
118+
18+
151+
104+

Do inline styles negatively impact performance?

No. Inline styles have significant performance advantages over stylesheets, including more efficient code-splitting and the elimination of render-blocking stylesheet requests. In Are Inline Styles Faster than CSS?, Daniel Nagy measures inline styles against stylesheets across rendering time, HTML and JavaScript size, browser performance, and Web Vitals, and finds that inline styles often outperform stylesheets. A 2026 benchmark thread comparing inline styles with static CSS reaches a similar conclusion.

What if my question is not answered here?

Start a discussion.