The sx Prop
The sx prop is a shortcut for defining custom styles with access to the theme. It’s available on all MUI components.
Basic Example
Key Features
Theme-aware
Access theme values using dot notation:Responsive
Define responsive styles with arrays or objects:Pseudo-selectors
Style hover, focus, and other states:Nested Selectors
Target child elements:Supported Properties
All CSS properties are supported, plus shorthand properties:m,mt,mr,mb,ml,mx,my- Marginp,pt,pr,pb,pl,px,py- Paddingbgcolor- Background color
Performance
Thesx prop is optimized for performance:
- Styles are memoized based on theme
- CSS is generated at build time when possible
- Only changed styles trigger re-renders
TypeScript
Full type safety withSxProps: