Quickstart Guide
This guide will walk you through creating a simple themed button component using Theme UI. You’ll learn the fundamentals of thesx 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
Create a theme file
First, let’s create a theme with button styles. Create or update your This theme defines:
theme.js file:theme.js
- Font and spacing scales that components can reference by index
- A color palette with semantic names
- Button variants with different styles
Add the ThemeUIProvider
Wrap your application with the provider. If you haven’t done this yet:
App.jsx
Create a custom button component
Create a new file called
Button.jsx and add the JSX pragma at the top:Button.jsx
Use responsive styles
Make your button responsive by using arrays for style values:The array syntax applies styles mobile-first:
Button.jsx
- First value: all viewports
- Second value: first breakpoint and up (typically 40em/640px)
- Third value: second breakpoint and up (typically 52em/832px)
Using Theme UI Components
Theme UI also provides pre-built components. Here’s how to use the built-inButton component:
Button component:
- Automatically references
theme.buttonsvariants - Supports the
sxprop 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
- The
sxprop: Apply styles that reference your theme - Theme values: Use semantic names and scale indices instead of hard-coded values
- Variants: Define reusable style patterns in your theme
- Responsive styles: Use arrays for mobile-first responsive design
- JSX pragma: Enable the
sxprop 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
