Skip to main content
The sx prop is the primary way to style elements with Theme UI. It provides theme-aware styling with automatic lookups to your theme’s design scales.

Basic Usage

The sx prop accepts a style object with CSS properties:

Theme Lookups

The sx prop automatically maps CSS properties to theme scales:

Example with Theme

Given this theme:
This component:

Property Aliases

Theme UI provides shorthand aliases for common CSS properties:
Example usage:

Nested Selectors

You can use nested selectors for more complex styling:

Pseudo-Selectors

All CSS pseudo-selectors are supported:

Example from Theme UI Source

Here’s a real example from the Theme UI codebase:

Media Queries

You can use media queries directly:
For responsive styles, use responsive arrays instead of media queries for a cleaner syntax.

Nested Scale Access

Access nested values in theme scales using dot notation:

Negative Values

Use negative values for margins and positioning:
With theme values:

Raw CSS Values

You can use raw CSS values that won’t be transformed:

The css Function

The sx prop uses the css function internally. You can use it directly:

Variants

Apply pre-defined style variants from your theme:

Function Values

Access the theme object directly with function values:

Type Safety

The sx prop is fully typed in TypeScript:
The sx prop provides a powerful, theme-aware styling API that makes it easy to build consistent, maintainable designs.