Skip to main content

Quickstart Guide

This guide will walk you through creating a simple themed button component using Theme UI. You’ll learn the fundamentals of the sx prop, theme values, and variant styling.
This guide assumes you’ve already installed Theme UI and set up the ThemeUIProvider in your application.

Create Your First Themed Component

1

Create a theme file

First, let’s create a theme with button styles. Create or update your theme.js file:
theme.js
This theme defines:
  • Font and spacing scales that components can reference by index
  • A color palette with semantic names
  • Button variants with different styles
2

Add the ThemeUIProvider

Wrap your application with the provider. If you haven’t done this yet:
App.jsx
3

Create a custom button component

Create a new file called Button.jsx and add the JSX pragma at the top:
Button.jsx
Don’t forget the /** @jsxImportSource theme-ui */ pragma! Without it, the sx prop won’t work.
4

Use responsive styles

Make your button responsive by using arrays for style values:
Button.jsx
The array syntax applies styles mobile-first:
  • First value: all viewports
  • Second value: first breakpoint and up (typically 40em/640px)
  • Third value: second breakpoint and up (typically 52em/832px)
5

Use theme variants

Instead of defining all styles inline, reference the button variant from your theme:
Button.jsx
Now you can use different button styles:

Using Theme UI Components

Theme UI also provides pre-built components. Here’s how to use the built-in Button component:
The built-in Button component:
  • Automatically references theme.buttons variants
  • Supports the sx prop for custom overrides
  • Includes default styles for common button properties
  • Uses variant="primary" by default
You can use the sx prop on Theme UI components to override or extend variant styles.

Complete Example

Here’s a complete working example with a theme, provider, and themed button:

Key Concepts Learned

  1. The sx prop: Apply styles that reference your theme
  2. Theme values: Use semantic names and scale indices instead of hard-coded values
  3. Variants: Define reusable style patterns in your theme
  4. Responsive styles: Use arrays for mobile-first responsive design
  5. JSX pragma: Enable the sx prop with /** @jsxImportSource theme-ui */

Next Steps

Now that you’ve built your first themed component, explore more features:

Color Modes

Add dark mode support to your application

Components

Explore Theme UI’s built-in components

Theming

Learn about the theme specification

Responsive Styles

Master responsive design patterns