Skip to main content
The jsx function is Theme UI’s custom JSX pragma that enables the sx prop on all elements. It wraps Emotion’s JSX function and processes the sx and css props.

Import

Signature

React.FunctionComponent<P> | React.ComponentClass<P> | string
required
The component type or HTML element name (e.g., ‘div’, ‘button’, or a React component)
React.Attributes & P
required
Props object that may include sx and css props
React.ReactNode[]
Child elements to render

How It Works

The jsx function performs the following steps:
  1. Receives JSX elements from the compiler
  2. Parses the sx prop using the Theme UI CSS function
  3. Transforms the sx prop into an Emotion css prop
  4. Passes the result to Emotion’s JSX function for rendering
This allows you to use the sx prop on any element:

Usage

Classic Runtime (Manual Pragma)

For the classic JSX runtime, add the pragma comment at the top of your file:
Or with the older pragma syntax:
Configure your build tool to use Theme UI’s JSX runtime automatically: TypeScript (tsconfig.json):
Babel (.babelrc):
With this configuration, you don’t need pragma comments:

Direct Usage

You can also call the jsx function directly:

Props Processing

The jsx function processes props through parseProps, which:
  1. Leaves props untouched if no sx or css prop is present
  2. Removes the sx prop from the final props
  3. Converts sx to Emotion’s css prop using Theme UI’s CSS function
  4. Preserves the existing css prop if present
  5. Both sx and css can be used together:

Internal Implementation

From packages/core/src/index.ts:39-43:
The parseProps function (packages/core/src/parseProps.tsx:9-21):

TypeScript Support

The jsx function includes full TypeScript definitions for JSX intrinsic elements and the sx prop. The JSX namespace is augmented to include:
  • Element
  • ElementClass
  • IntrinsicElements (with sx prop)
  • IntrinsicAttributes

Examples from Tests

Basic sx Prop

Raw CSS Prop

CSS Prop with Function

Combined sx and css