Skip to main content
The CSS Helper is experimental. The API may change in future versions.
The CSS Helper provides CSS-in-JS functionality with automatic scoping, allowing you to write CSS directly in your TypeScript/JavaScript code.

Import

Functions

css()

Defines scoped CSS styles and returns a unique class name.
TemplateStringsArray
required
The CSS template string
CssVariableType[]
required
Values to interpolate into the CSS (variables, other css() results, etc.)
Promise<string>
A unique class name for the scoped styles
Example

cx()

Combines multiple class names, similar to the popular classnames library.
(CssClassName | Promise<string> | string | boolean | null | undefined)[]
required
Class names to combine. Falsy values are ignored.
Promise<string>
Combined class names as a single string
Example

keyframes()

Defines CSS keyframe animations.
TemplateStringsArray
required
The keyframes template string
CssVariableType[]
required
Values to interpolate
CssClassNameCommon
A keyframes name that can be used in CSS animations
Example

Style()

Renders the <style> tag containing all accumulated CSS.
Promise<string>
Optional CSS content to include in the style tag
string
Optional nonce attribute for Content Security Policy
HtmlEscapedString
A style tag containing all CSS styles used in the current render
Example

viewTransition()

Creates styles for view transitions API.
TemplateStringsArray
The CSS template for view transition
CssVariableType[]
Values to interpolate
Promise<string>
A view transition name
Example

createCssContext()

Creates an isolated CSS context with a custom style ID.
string
required
A unique identifier for the style tag
object
An object containing isolated versions of css, cx, keyframes, viewTransition, and Style
Example

Features

Automatic Scoping

All styles defined with css() are automatically scoped with unique class names, preventing style conflicts:

Nesting Support

Supports CSS nesting for pseudo-classes and nested selectors:

CSS Variables

Interpolate values and other styles:

Performance Considerations

  • Styles are generated on-demand during rendering
  • Duplicate styles are automatically deduplicated
  • The Style component must be included in the <head> for styles to render

Types