sx prop
Thesx 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
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
- All CSS properties with theme-aware values
- Pseudo-selectors (
:hover,:focus, etc.) - Custom CSS selectors
- Variant references
- Label for Emotion class names
ThemeDerivedStyles
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:null, undefined, or false are ignored:
Shorthand Aliases
Thesx prop supports convenient shorthand properties:
m- marginmt- marginTopmr- marginRightmb- marginBottomml- marginLeftmx- marginLeft + marginRightmy- marginTop + marginBottom
p- paddingpt- paddingToppr- paddingRightpb- paddingBottompl- paddingLeftpx- paddingLeft + paddingRightpy- paddingTop + paddingBottom
bg- backgroundColor
marginX- marginLeft + marginRightmarginY- marginTop + marginBottompaddingX- paddingLeft + paddingRightpaddingY- paddingTop + paddingBottomscrollMarginX- scrollMarginLeft + scrollMarginRightscrollMarginY- scrollMarginTop + scrollMarginBottomscrollPaddingX- scrollPaddingLeft + scrollPaddingRightscrollPaddingY- scrollPaddingTop + scrollPaddingBottomsize- width + height
Theme-Aware Properties
Certain CSS properties automatically look up values from the theme. Here’s the complete mapping:Colors
Maps totheme.colors:
colorbackgroundColor,background,bgborderColor,borderTopColor,borderBottomColor,borderLeftColor,borderRightColorborderBlockColor,borderBlockEndColor,borderBlockStartColorborderInlineColor,borderInlineEndColor,borderInlineStartColorcaretColorcolumnRuleColoroutlineColortextDecorationColoraccentColorfill,stroke(SVG properties)
Space
Maps totheme.space:
- 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
fontFamily→theme.fontsfontSize→theme.fontSizesfontWeight→theme.fontWeightslineHeight→theme.lineHeightsletterSpacing→theme.letterSpacings
Borders
border,borderTop,borderRight,borderBottom,borderLeft→theme.borders- All border block/inline properties →
theme.borders borderWidth,borderTopWidth,borderBottomWidth, etc. →theme.borderWidthsborderStyle,borderTopStyle,borderBottomStyle, etc. →theme.borderStylesborderRadius,borderTopLeftRadius,borderTopRightRadius, etc. →theme.radiicolumnRuleWidth→theme.borderWidths
Sizes
width,minWidth,maxWidth→theme.sizesheight,minHeight,maxHeight→theme.sizesflexBasis→theme.sizessize→theme.sizesblockSize,minBlockSize,maxBlockSize→theme.sizesinlineSize,minInlineSize,maxInlineSize→theme.sizescolumnWidth→theme.sizes
Other Scales
boxShadow,textShadow→theme.shadowszIndex→theme.zIndicesopacity→theme.opacitiestransition→theme.transitions
Pseudo-Selectors
All CSS pseudo-selectors are supported:CSS Selectors
Custom CSS selectors are supported through an index signature:Variants
Reference predefined variants from the theme:Nested Theme Values
Theme scales can be nested using the__default key:
