css
Thecss function is the core styling utility in Theme UI. It processes style objects, performs theme lookups, handles responsive arrays, and transforms shorthand properties into their full CSS equivalents.
Function Signature
Parameters
Style object containing CSS properties, aliases, and theme-aware values. Can be:
- Plain style object with CSS properties
- Function that receives the theme and returns a style object
- Object with responsive arrays for mobile-first styling
- Object with variant references
Returns
Returns a function that accepts a theme object (or
{ theme } prop object) and returns the final CSS object with all transformations applied.How It Works
1. Theme Lookups
Thecss function automatically looks up values from theme scales based on the CSS property:
2. Responsive Arrays
Arrays are transformed into mobile-first media queries using the theme’s breakpoints:3. Property Aliases
Shorthand properties are expanded to their full CSS equivalents:Available Aliases
bg→backgroundColorm→marginmt→marginTopmr→marginRightmb→marginBottomml→marginLeftmx→marginX(expands to left + right)my→marginY(expands to top + bottom)p→paddingpt→paddingToppr→paddingRightpb→paddingBottompl→paddingLeftpx→paddingX(expands to left + right)py→paddingY(expands to top + bottom)
4. Multiple Properties
Some properties expand to multiple CSS properties:Available Multiples
marginX→marginLeft,marginRightmarginY→marginTop,marginBottompaddingX→paddingLeft,paddingRightpaddingY→paddingTop,paddingBottomscrollMarginX→scrollMarginLeft,scrollMarginRightscrollMarginY→scrollMarginTop,scrollMarginBottomscrollPaddingX→scrollPaddingLeft,scrollPaddingRightscrollPaddingY→scrollPaddingTop,scrollPaddingBottomsize→width,height
5. Negative Values
Certain properties (margins, positioning) support negative values:6. Nested Scales with __default
Theme scales can be nested with a __default key:
7. Variant References
Reference predefined variants from the theme:Theme Scale Mappings
Thecss function maps CSS properties to theme scales automatically:
Colors
Colors
Maps to
theme.colors:colorbackgroundColor,backgroundborderColor,borderTopColor,borderBottomColor,borderLeftColor,borderRightColorborderBlockColor,borderBlockEndColor,borderBlockStartColorborderInlineColor,borderInlineEndColor,borderInlineStartColorcaretColorcolumnRuleColoroutlineColortextDecorationColoraccentColorfill,stroke(SVG)
Space
Space
Maps to
theme.space:margin,marginTop,marginRight,marginBottom,marginLeftmarginX,marginYmarginBlock,marginBlockEnd,marginBlockStartmarginInline,marginInlineEnd,marginInlineStartpadding,paddingTop,paddingRight,paddingBottom,paddingLeftpaddingX,paddingYpaddingBlock,paddingBlockEnd,paddingBlockStartpaddingInline,paddingInlineEnd,paddingInlineStarttop,right,bottom,leftinset,insetBlock,insetBlockEnd,insetBlockStartinsetInline,insetInlineEnd,insetInlineStartscrollMargin,scrollMarginTop,scrollMarginRight,scrollMarginBottom,scrollMarginLeftscrollMarginX,scrollMarginYscrollPadding,scrollPaddingTop,scrollPaddingRight,scrollPaddingBottom,scrollPaddingLeftscrollPaddingX,scrollPaddingYgap,gridGap,columnGap,gridColumnGap,rowGap,gridRowGap
Typography
Typography
fontFamily→theme.fontsfontSize→theme.fontSizesfontWeight→theme.fontWeightslineHeight→theme.lineHeightsletterSpacing→theme.letterSpacings
Borders
Borders
border,borderTop,borderRight,borderBottom,borderLeft→theme.bordersborderBlock,borderBlockEnd,borderBlockStart→theme.bordersborderInline,borderInlineEnd,borderInlineStart→theme.bordersborderWidth,borderTopWidth,borderBottomWidth,borderLeftWidth,borderRightWidth→theme.borderWidthsborderBlockWidth,borderBlockEndWidth,borderBlockStartWidth→theme.borderWidthsborderInlineWidth,borderInlineEndWidth,borderInlineStartWidth→theme.borderWidthsborderStyle,borderTopStyle,borderBottomStyle,borderLeftStyle,borderRightStyle→theme.borderStylesborderBlockStyle,borderBlockEndStyle,borderBlockStartStyle→theme.borderStylesborderInlineStyle,borderInlineEndStyle,borderInlineStartStyle→theme.borderStylescolumnRuleWidth→theme.borderWidths
Radii
Radii
Maps to
theme.radii:borderRadiusborderTopLeftRadius,borderTopRightRadiusborderBottomLeftRadius,borderBottomRightRadiusborderEndEndRadius,borderEndStartRadiusborderStartEndRadius,borderStartStartRadius
Sizes
Sizes
Maps to
theme.sizes:width,minWidth,maxWidthheight,minHeight,maxHeightflexBasissizeblockSize,minBlockSize,maxBlockSizeinlineSize,minInlineSize,maxInlineSizecolumnWidth
Other Scales
Other Scales
boxShadow,textShadow→theme.shadowszIndex→theme.zIndicesopacity→theme.opacitiestransition→theme.transitions
Default Theme
If no theme is provided,css uses these defaults:
