Skip to main content
The JSX pragma is how Theme UI enables the sx prop on all HTML elements. This guide covers how to configure your project to use the sx prop. Theme UI supports React’s automatic JSX runtime, which is the recommended approach for modern React applications. With automatic runtime, you don’t need to import React in every file.

Configuration

Add the jsxImportSource comment at the top of your file:
The @jsxImportSource pragma must be at the very top of your file, before any imports.

TypeScript Configuration

For TypeScript projects, update your tsconfig.json:
This sets Theme UI as the default JSX import source for all files. You can still override it per-file using the @jsxImportSource comment.

Next.js Example

How It Works

Theme UI provides its own JSX runtime that wraps Emotion’s JSX functions. When you use the @jsxImportSource pragma, your JSX is transformed using Theme UI’s custom runtime.

Implementation Details

The Theme UI JSX runtime processes the sx prop before passing elements to Emotion:
The parseProps function converts the sx prop into Emotion’s css prop:

Using @theme-ui/core

For minimal bundle size, you can use @theme-ui/core which provides the essential JSX runtime without additional components:
@theme-ui/core doesn’t add global or root styles. Use the full theme-ui package if you need those features.

Classic JSX Runtime (Legacy)

The classic JSX pragma is deprecated. Use the automatic runtime instead.
If you’re using an older React version (< 17), you can use the classic JSX pragma:

Troubleshooting

TypeScript Errors

If you’re getting TypeScript errors with the sx prop, make sure you’re using TypeScript 5.1.2 or newer:
Theme UI v0.16+ requires TypeScript 5.1.2+ and @types/react published after June 1, 2023.

Mixing Runtimes

You can mix both the automatic runtime and explicit css prop usage:

CSS Prop vs SX Prop

The sx prop is transformed into the css prop at build time. You can use both:
  • sx - Theme-aware, has access to theme values
  • css - Raw Emotion styles, useful for complex CSS

Migration Guide

Moving from the classic runtime to automatic runtime:
The main differences:
  1. Change @jsx jsx to @jsxImportSource theme-ui
  2. Remove the import { jsx } from 'theme-ui' statement
  3. No other code changes needed!