Installation
Get started with Theme UI by installing the package and its peer dependencies.Prerequisites
Theme UI requires the following in your project:- Node.js: Version 18.0.0 or higher
- React: Version 18 or higher
Install Dependencies
Theme UI has a peer dependency on@emotion/react, which must be installed alongside the main package.
The
theme-ui package includes all features: the sx prop, color modes, and UI components. If you don’t need color modes or components, you can install the lighter @theme-ui/core package instead.Lightweight Alternative
For a minimal installation without color modes or components:Setup
After installation, set up Theme UI in your application by creating a theme and wrapping your app with theThemeUIProvider.
Step 1: Create a Theme
Create a theme file that defines your design tokens. The theme object follows the System UI Theme Specification. Create a file calledtheme.js (or theme.ts for TypeScript):
theme.js
Step 2: Add the Provider
Wrap your application with theThemeUIProvider component and pass in your theme object.
App.jsx
The
ThemeUIProvider should be placed at the root of your application to make the theme available to all components.Step 3: Enable the sx Prop
To use the sx prop in your components, add the JSX pragma comment at the top of each file:
/** @jsxImportSource theme-ui */ pragma tells your build tool to use Theme UI’s custom JSX function, which enables the sx prop.
TypeScript Support
Theme UI includes full TypeScript definitions. No additional setup is required for TypeScript support.Verify Installation
To verify that Theme UI is installed correctly, create a simple component using thesx prop:
test.jsx
Next Steps
Quickstart
Learn how to create your first themed component
