material-ui-best-practices
Material-UI Best Practices
Comprehensive guide for building performant, accessible, and maintainable applications with Material-UI (MUI). Contains best practices across multiple categories, including theming, performance optimization, accessibility, and component usage.
When to Apply
Reference these guidelines when:
- Writing new components with Material-UI
- Implementing custom themes or design systems
- Optimizing MUI application performance
- Reviewing code for accessibility compliance
- Refactoring existing MUI code
- Choosing between different MUI styling approaches
Rule Categories
| Category | Focus Area | Prefix |
|---|---|---|
| 1 | Theme & Styling | theme- |
| 2 | Performance Optimization | perf- |
| 3 | Component Usage | component- |
| 4 | Accessibility | a11y- |
| 5 | Bundle Size | bundle- |
| 6 | TypeScript & Type Safety | types- |
Quick Reference
1. Theme & Styling
theme-provider-root- Always wrap app with ThemeProvider at root leveltheme-custom-colors- Extend theme palette for custom colors instead of inline stylestheme-responsive-values- Use theme breakpoints for responsive designtheme-spacing-function- Use theme.spacing() for consistent spacingtheme-typography- Leverage theme typography variantstheme-dark-mode- Implement dark mode using theme mode toggletheme-css-baseline- Include CssBaseline for consistent resets
2. Performance Optimization
perf-sx-prop-static- Extract static sx prop values to constantsperf-avoid-inline-styles- Avoid inline style objects in renderperf-styled-outside-render- Define styled components outside render functionsperf-use-memo-expensive-computations- Memoize expensive theme/style computationsperf-emotion-cache- Configure Emotion cache for SSRperf-tree-shaking- Import components individually for tree-shaking
3. Component Usage
component-prop-forwarding- Use component prop for semantic HTMLcomponent-icon-sizing- Use fontSize prop for Icon sizingcomponent-button-variants- Choose appropriate Button variantcomponent-grid-vs-stack- Use Stack for simple layouts, Grid for complexcomponent-dialog-composition- Compose Dialog with semantic sub-componentscomponent-form-control- Group related form inputs with FormControlcomponent-controlled-inputs- Use controlled components for form inputs
4. Accessibility
a11y-aria-labels- Provide aria-label for icon-only buttonsa11y-focus-visible- Preserve focus indicatorsa11y-color-contrast- Ensure sufficient color contrasta11y-keyboard-navigation- Support keyboard navigationa11y-screen-reader- Use proper semantic HTML and ARIA attributesa11y-form-labels- Associate labels with form controls
5. Bundle Size
bundle-direct-imports- Import directly from @mui/material/Componentbundle-icons-separate- Load icons from @mui/icons-material separatelybundle-lab-components- Import lab components individuallybundle-date-pickers- Use date picker adapters judiciously
6. TypeScript & Type Safety
types-theme-augmentation- Augment theme types for custom propertiestypes-component-props- Use MUI's component prop typestypes-sx-prop- Leverage SxProps type for sx proptypes-override-types- Extend component variant types properly
Directory Structure
skills/material-ui-best-practices/
├── SKILL.md # This file - skill overview
├── AGENTS.md # Complete compiled guide for agents
├── metadata.json # Skill metadata
├── README.md # User-facing documentation
└── rules/ # Individual rule files
├── theme-provider-root.md
├── perf-sx-prop-static.md
└── ...
How to Use
Read individual rule files for detailed explanations and code examples:
rules/theme-provider-root.md
rules/perf-sx-prop-static.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
References
More from blackbytessa/agent-skills
javascript-best-practices
Modern JavaScript best practices and performance optimization guidelines. Use when writing, reviewing, or refactoring JavaScript code to ensure optimal performance, maintainability, and modern patterns.
8web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
1vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
1vercel-composition-patterns
React composition patterns that scale. Use when refactoring components with
1vercel-react-native-skills
React Native and Expo best practices for building performant mobile apps. Use
1