AGENTS.md
skills/material-ui-styling/AGENTS.mdAGENTS.md
Quality
58/100
Scores the file, not the repository.Length
943 words
11 headings · 2 code blocksRepository
99k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Material UI styling23Version 1.0.0 (Material UI v9)45> **Version notice:** This skill targets Material UI v9 (`>=9.0.0 <10.0.0`). If you are using a different major version, verify the API details before following this guidance.67> Note: This document is for agents and LLMs maintaining or generating Material UI code. It follows [How to customize](https://mui.com/material-ui/customization/how-to-customize.md) and related sources in this repository (`docs/data/material/customization/`, `docs/data/system/`).89---1011## Abstract1213Material UI stacks four strategies from narrowest to broadest scope. Pick the smallest scope that solves the problem to avoid scattering global rules. The `sx` prop is the default for one-off tweaks; `styled()` is for reusable wrappers; the theme's `components` API is for app-wide consistency; `GlobalStyles` / `CssBaseline` is for baseline HTML or cross-cutting globals.1415---1617## Table of contents18191. [Quick decision (use in order)](#quick-decision-use-in-order)202. [One-off: `sx` prop](#1-one-off-sx-prop)213. [Reusable: `styled()`](#2-reusable-styled)224. [Global theme: `createTheme({ components })`](#3-global-theme-createtheme-components)235. [Global CSS: `GlobalStyles` / `CssBaseline`](#4-global-css-globalstyles--cssbaseline)246. [`sx` vs `styled()`](#sx-vs-styled-differences-agents-should-know)257. [Imports and consistency](#imports-and-consistency)268. [Further reading](#further-reading-repo--site)2728---2930## Quick decision (use in order)31321. Single instance or local layout? → [`sx`](https://mui.com/system/getting-started/the-sx-prop/)332. Same override in many places? → [`styled()`](https://mui.com/system/styled/) around the MUI component (or a thin wrapper component)343. All instances of a component should look different by default? → [`theme.components`](https://mui.com/material-ui/customization/theme-components.md) (`styleOverrides`, `variants`, `defaultProps`)354. Global element baselines (for example all `h1`) or non-component CSS? → [`GlobalStyles`](https://mui.com/material-ui/api/global-styles.md) or [`CssBaseline`](https://mui.com/material-ui/react-css-baseline.md) overrides3637Do not jump to global theme overrides for a one-off screen; do not use `sx` for large repeated systems if a themed variant or `styled()` wrapper is clearer.3839---4041## 1. One-off: `sx` prop4243Use when: changing one instance (or a small inline case) with access to the theme.4445- All Material UI components support `sx`.46- Supports theme shortcuts (`palette`, `spacing`, breakpoints, etc.), pseudo-selectors, nested selectors, and responsive objects.47- Array syntax: `sx={[base, condition && extra]}` merges styles conditionally — entries applied in order, falsy entries skipped. Prefer this over object spread for conditional `sx`.4849Nested parts (slots): target internal slots with global class fragments, for example `'& .MuiSlider-thumb'`. Discover the slot name in DevTools; the pattern is `Mui[Component]-[slot]`. Do not rely on the full hashed class string. Use only the stable `Mui*` fragment.5051State styles: MUI uses global state classes (`.Mui-disabled`, `.Mui-selected`, etc.) with specificity comparable to pseudo-classes. Override with increased specificity (for example combine with your class or the component root), never bare global state selectors alone.5253```css54/* Bad: affects every component using .Mui-error */55.Mui-error {56 color: red;57}5859/* Good: scoped to OutlinedInput root */60.MuiOutlinedInput-root.Mui-error {61 color: red;62}63```6465See [How to customize—State classes](https://mui.com/material-ui/customization/how-to-customize.md#state-classes).6667`className`: use when integrating with external CSS or CSS Modules; combine with the same slot/state rules as above.6869---7071## 2. Reusable: `styled()`7273Use when: the same customized component appears in multiple places and deserves a named component.7475```ts76import { styled } from '@mui/material/styles';77```7879- Prefer `@mui/material/styles` when using Material UI so the default theme matches the rest of the app.80- `styled()` adds theme integration, optional `name` / `slot` for theme overrides, and `sx` on the result (unless disabled).81- For custom props, use `shouldForwardProp` so DOM/React does not receive invalid attributes. Extend the component's prop types in TypeScript.8283Dynamic styling: prefer CSS variables or conditional style objects in the style callback; avoid per-field functions inside the style object for readability (see [styled() docs](https://mui.com/system/styled/)).8485---8687## 3. Global theme: `createTheme({ components })`8889Use when: default look of `Button`, `TextField`, etc. should change everywhere.9091- `defaultProps`: change defaults (for example `disableRipple` on `MuiButtonBase`).92- `styleOverrides`: target slots (`root`, `input`, …) with plain CSS-in-JS objects; nested selectors allowed. Use the callback form `root: ({ ownerState, theme }) => ({ ... })` to branch on the component's resolved props without extra class names.93- `variants`: map props to extra styles (built-in props like `variant: 'outlined'` or custom values you document for your design system).9495Caveat: the theme is not tree-shakable. For heavy one-off customizations, a new component is often better than bloating the theme.9697Full API: [Themed components](https://mui.com/material-ui/customization/theme-components.md).9899---100101## 4. Global CSS: `GlobalStyles` / `CssBaseline`102103Use when: styling raw HTML elements or app-wide snippets that are not tied to a single MUI component instance.104105- Prefer hoisting `<GlobalStyles />` to a module-level constant so the style tag does not churn on re-renders.106- `styles` can be a callback for theme access.107- Can extend `MuiCssBaseline` `styleOverrides` if the app already uses `CssBaseline`.108109---110111## `sx` vs `styled()`: differences agents should know112113| Topic | `sx` | `styled()` style object |114| :------------------------------------------- | :----------------- | :----------------------------------------------------------- |115| Theme spacing shorthand (`m`, `p`, `gap`, …) | Yes | No. Use `theme.spacing()` in a function or plain CSS values. |116| Meaning of numeric padding like `1` | Theme spacing unit | Pixels, not `theme.spacing(1)` |117| Theme palette strings (`'primary.main'`) | Yes | Use `theme` in a function |118119To reuse `sx` logic inside `styled()`, use theme's `unstable_sx` (see [styled()—Difference with the sx prop](https://mui.com/system/styled/#difference-with-the-sx-prop)).120121---122123## Imports and consistency124125- In application code, prefer one-level imports from packages (for example `@mui/material/Button`) to avoid pulling the entire barrel.126- Use `sx` for system layout shortcuts (`p`, `gap`, `mt`, etc.) on MUI components; use component props only for behavior documented by that component.127128---129130## Further reading (repo / site)131132| Topic | Doc |133| :---------------------- | :------------------------------------------------------------------------------------------- |134| Choosing strategy | [How to customize](https://mui.com/material-ui/customization/how-to-customize.md) |135| `sx` reference | [The sx prop](https://mui.com/system/getting-started/the-sx-prop/) |136| `styled()` API | [styled()](https://mui.com/system/styled/) |137| Theme per component | [Themed components](https://mui.com/material-ui/customization/theme-components.md) |138| System property mapping | [System properties](https://mui.com/system/properties/) |139| State / class naming | [State classes](https://mui.com/material-ui/customization/how-to-customize.md#state-classes) |140141For MUI-specific class and state tables, see [reference.md](reference.md).142
Also in mui/material-ui
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| mui/material-uiskills/material-ui-nextjs/AGENTS.md · 99k | AGENTS.md | setupstylearchtypes+2 | 70/100 | 3 days ago | |
| mui/material-uiskills/material-ui-tailwind/AGENTS.md · 99k | AGENTS.md | styleui | 58/100 | 3 days ago | |
| mui/material-uiskills/material-ui-theming/AGENTS.md · 99k | AGENTS.md | setupstyleui | 58/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| wpscanteam/wpscanAGENTS.md · 9.7k | AGENTS.md | setupbuildteststyle+6 | 100/100 | 2 days ago | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago |
