Skip to main content
Brand and assets
BuildMonitor and contribute
/
Brand and assets
  • Foundations
    • The brand
    • Logo
    • Colors
    • Typography
    • Styles
    • Shadows & radii
    • Spacing & grid
    • Gradients
    • Styling & the sx prop
    • Color tokens
    • More
    • Accessibility
  • Assets
  • AI references
  • Foundations
  • Styling & the sx prop

Styling

While some legacy components allow overriding all styles through the style props, new components are more restrictive. This is to ensure that the components look consistent across products and that we can safely make changes to the components without breaking existing products.

sx prop​

Recent components never expose the style prop. Some of them instead have a sx prop, which have the same purpose but allow accessing design tokens from the theme. Styling through sx is compatible with both web and mobile platforms. Under the hood it converts the styles to CSS on web, and to native Stylesheet on mobile.

<Box sx={{ backgroundColor: "$indigo.500", color: "#fff", width: "$px98", height: 50 }}>
Box with custom colors, using a mix of design tokens and raw values.
</Box>

Universal compatibility​

The sx prop is designed to be universal across platforms (web, iOS, and Android). This means that some property values may not be available on all platforms, as they need to be compatible with React Native's styling system. For example, you can use position but it'll be omitted for native, additionally the display property is valid, but display: "grid" is only available on web.

Platform-specific styling​

When you need to target specific platforms, you can use platform-specific keys in the sx prop:

<Box
sx={{
color: "$indigo500",
$platform-web: {
display: "grid",
gridTemplateColumns: "repeat(2, 1fr)",
columnGap: "$px32",
},
$platform-native: {
display: "flex",
flexDirection: "row",
gap: "$px16",
},
$platform-ios: {
backgroundColor: "$gray900",
},
$platform-android: {
backgroundColor: "$green500",
},
}}
>
Platform-specific styling
</Box>

Pseudo styles​

It's also possible to style pseudo states such as "hover", "press" and "focus" through sx:

<Box
sx={{
backgroundColor: "$indigo500",
hoverStyle: { backgroundColor: "$indigo700" },
pressStyle: { backgroundColor: "$indigo300" },
}}
>
Box with pseudo styles
</Box>

Responsive styles​

Responsive styles can be defined through the sx prop:

<Box sx={{ padding: "$px8", $md: { padding: "$px16" } }}>Box with responsive padding</Box>

css & className props​

caution

The css prop should never be used to target children of a Murray components. Doing so might break in the future as there is no guarantee that the inner structure of the component will stay the same.

The sx props is a universal implementation that needs to be compatible with both mobile and web platforms. On web, it it sometimes useful to rely on Emotion's css prop as an escape hatch for usecases not handled by sx.

The css prop is available on some low-level components such as VStack/HStack and Box:

<Box css={{ background: "linear-gradient(134deg, #EBF5FF 3.96%, #FFF0E0 106.89%)" }}>
Box using the css prop to set a CSS background gradient as it can't be done through sx
</Box>
Edit this page
Previous
Gradients
Next
Color tokens
  • sx prop
    • Universal compatibility
    • Platform-specific styling
    • Pseudo styles
    • Responsive styles
  • css & className props