Skip to main content

sx prop

The sx prop is the primary way to style components in Theme UI. It accepts all CSS properties with theme-aware values, shorthand aliases, and responsive arrays. This page documents the TypeScript types that power the sx prop.

Type Definition

The sx prop accepts a ThemeUIStyleObject which can be:
  • A plain style object (ThemeUICSSObject)
  • A function that receives the theme and returns a style object (ThemeDerivedStyles)

Core Types

ThemeUICSSObject

This is the main type for style objects. It includes:
  • All CSS properties with theme-aware values
  • Pseudo-selectors (:hover, :focus, etc.)
  • Custom CSS selectors
  • Variant references
  • Label for Emotion class names

ThemeDerivedStyles

Allows styles to be defined as a function that receives the theme:

CSS Properties

Standard Properties

All standard CSS properties are supported with responsive and theme-aware values:

Responsive Values

Every CSS property accepts arrays for mobile-first responsive styling:
Example:
Values of null, undefined, or false are ignored:

Shorthand Aliases

The sx prop supports convenient shorthand properties:
Margin Aliases:
  • m - margin
  • mt - marginTop
  • mr - marginRight
  • mb - marginBottom
  • ml - marginLeft
  • mx - marginLeft + marginRight
  • my - marginTop + marginBottom
Padding Aliases:
  • p - padding
  • pt - paddingTop
  • pr - paddingRight
  • pb - paddingBottom
  • pl - paddingLeft
  • px - paddingLeft + paddingRight
  • py - paddingTop + paddingBottom
Other Aliases:
  • bg - backgroundColor
Extended Aliases:
  • marginX - marginLeft + marginRight
  • marginY - marginTop + marginBottom
  • paddingX - paddingLeft + paddingRight
  • paddingY - paddingTop + paddingBottom
  • scrollMarginX - scrollMarginLeft + scrollMarginRight
  • scrollMarginY - scrollMarginTop + scrollMarginBottom
  • scrollPaddingX - scrollPaddingLeft + scrollPaddingRight
  • scrollPaddingY - scrollPaddingTop + scrollPaddingBottom
  • size - width + height

Theme-Aware Properties

Certain CSS properties automatically look up values from the theme. Here’s the complete mapping:

Colors

Maps to theme.colors:
All color properties:
  • color
  • backgroundColor, background, bg
  • borderColor, borderTopColor, borderBottomColor, borderLeftColor, borderRightColor
  • borderBlockColor, borderBlockEndColor, borderBlockStartColor
  • borderInlineColor, borderInlineEndColor, borderInlineStartColor
  • caretColor
  • columnRuleColor
  • outlineColor
  • textDecorationColor
  • accentColor
  • fill, stroke (SVG properties)

Space

Maps to theme.space:
All space properties:
  • All margin properties: margin, marginTop, marginRight, marginBottom, marginLeft, marginX, marginY
  • All margin logical properties: marginBlock, marginBlockEnd, marginBlockStart, marginInline, marginInlineEnd, marginInlineStart
  • All padding properties: padding, paddingTop, paddingRight, paddingBottom, paddingLeft, paddingX, paddingY
  • All padding logical properties: paddingBlock, paddingBlockEnd, paddingBlockStart, paddingInline, paddingInlineEnd, paddingInlineStart
  • Positioning: top, right, bottom, left
  • Inset properties: inset, insetBlock, insetBlockEnd, insetBlockStart, insetInline, insetInlineEnd, insetInlineStart
  • Scroll margins: scrollMargin, scrollMarginTop, scrollMarginRight, scrollMarginBottom, scrollMarginLeft, scrollMarginX, scrollMarginY
  • Scroll padding: scrollPadding, scrollPaddingTop, scrollPaddingRight, scrollPaddingBottom, scrollPaddingLeft, scrollPaddingX, scrollPaddingY
  • Gaps: gap, gridGap, columnGap, gridColumnGap, rowGap, gridRowGap

Typography

Typography mappings:
  • fontFamilytheme.fonts
  • fontSizetheme.fontSizes
  • fontWeighttheme.fontWeights
  • lineHeighttheme.lineHeights
  • letterSpacingtheme.letterSpacings

Borders

Border mappings:
  • border, borderTop, borderRight, borderBottom, borderLefttheme.borders
  • All border block/inline properties → theme.borders
  • borderWidth, borderTopWidth, borderBottomWidth, etc. → theme.borderWidths
  • borderStyle, borderTopStyle, borderBottomStyle, etc. → theme.borderStyles
  • borderRadius, borderTopLeftRadius, borderTopRightRadius, etc. → theme.radii
  • columnRuleWidththeme.borderWidths

Sizes

Size mappings:
  • width, minWidth, maxWidththeme.sizes
  • height, minHeight, maxHeighttheme.sizes
  • flexBasistheme.sizes
  • sizetheme.sizes
  • blockSize, minBlockSize, maxBlockSizetheme.sizes
  • inlineSize, minInlineSize, maxInlineSizetheme.sizes
  • columnWidththeme.sizes

Other Scales

Other mappings:
  • boxShadow, textShadowtheme.shadows
  • zIndextheme.zIndices
  • opacitytheme.opacities
  • transitiontheme.transitions

Pseudo-Selectors

All CSS pseudo-selectors are supported:
Example:

CSS Selectors

Custom CSS selectors are supported through an index signature:
Example:

Variants

Reference predefined variants from the theme:
Example:
You can extend variants with additional styles:

Nested Theme Values

Theme scales can be nested using the __default key:
Example:

Special Properties

Label

Emotional label for debugging:
Example:

Type Overrides

Some CSS properties accept additional types for theme compatibility:
This allows you to use theme keys or indices:

Examples

Responsive Layout

Component with Variants and States

Nested Selectors

Theme Function Form

  • css - The underlying function that processes sx prop styles
  • get - Function used to extract theme values