8 min read
Why inline sx turns a long-running MUI project into a maintenance problem
sx is fine for one element. Spread across a codebase it hardcodes design decisions at every call site, lets components drift apart, costs render time and keeps you out of Server Components. What MUI itself recommends instead, with sources.
By the Colored Strategies team
Open any MUI codebase that is two years old and search for sx={. You will find
something like this, in three files written by three people:
<Card sx={{ borderRadius: 2, p: 2 }}>
<Card sx={{ borderRadius: "12px", padding: "20px" }}>
<Card sx={{ borderRadius: 3, px: 3, py: 2.5 }}>Three cards, three radii, three paddings, and no single place that says what a card looks like in this product. Nobody decided that. Each line was reasonable on the day it was written.
That is the problem with sx at the call site. Not that it is broken, but that every
use is a small, local design decision, and a long project makes thousands of them.
We sell admin templates built on MUI, and we watched this happen in our own code
before we moved the styling out. Here is the case against it, with sources,
and what to do instead.
MUI itself limits sx to one element
MUI is not ambiguous about this. Its "How to customize" guide lists four levels,
from narrowest to broadest, and gives sx the narrowest:
"The sx prop is the best option for adding style overrides to a single instance of a component in most cases." MUI, How to customize
For anything used twice, the same page points to a reusable component, and for consistency across the product, to the theme, which "provides theme tools for managing style consistency between all components across your user interface."
The System documentation says it again: "The sx prop is best suited for applying
one-off styles to custom components"
(MUI, Usage). In most codebases that
run into trouble, sx is not being used for one-offs. It is the default way to style
anything.
It lets components drift apart
A style written at the call site belongs to that call site. When the design changes, it does not change with it. Spotify's design system team described exactly this when writing about local customisation:
Local overrides "are less likely to be in close alignment with the system's broader standards" and "will stay in place, even if the official version changes drastically." Spotify Engineering, Customization vs. Configuration in Evolving Design Systems
On an admin panel this shows up slowly. The tables on the screens built in the first month have one row height, the ones built in month nine have another. Two dialogs have different button spacing because one was copied from a Stack Overflow answer. None of it is a bug, so none of it gets a ticket, and after a year the product looks assembled rather than designed.
sx makes the drift easy in two ways. It accepts raw values, so "12px" and
"#3C87B7" sit next to theme keys with nothing to tell them apart. And it lives in
JSX, where a reviewer reads it as code, not as a design decision. Atlassian treats
hardcoded values as violations outright, and enforces it with a lint rule:
"Using anything other than design tokens such as hardcoded values or legacy theme colors will be considered violations." Atlassian Design System, ensure-design-token-usage
It takes away the one place to change things
When the designer asks for slightly rounder cards, the answer should be one line.
With styling in the theme or in a component stylesheet, it is. With styling in sx,
it is a search across the codebase, a judgement call on every match (is this 2 a
card radius or something else?), and a pull request nobody wants to review.
Brad Frost's advice for design systems applies directly: teams should "periodically
audit these one-off components", and "as the system matures the number of custom
components should trend downwards"
(Brad Frost, Where to put one-off components?).
In an sx-heavy codebase that number usually goes the other way, because the
cheapest fix for any visual problem is one more sx.
It costs render time
sx is resolved at runtime. Every render turns the object into CSS through Emotion.
MUI documents the cost on its own Usage page, rendering 1,000 elements:
| 1,000 elements | Relative time |
|---|---|
| A div with className | 100 ms |
| A styled() component | 181 ms |
| A Box with sx | 296 ms |
MUI's own verdict is that "runtime performance takes a hit" but that "for most use cases it's fast enough" (MUI, Usage: performance tradeoffs). That is fair for a marketing page. An admin panel is the worst case: data grids, long lists, forms with dozens of fields, re-rendering on every keystroke.
Two outside data points:
- Sam Magura, then the second most active maintainer of Emotion, measured a component at Spot rendering in 54.3 ms with Emotion and 27.7 ms after moving to Sass Modules, and wrote the team was breaking up with runtime CSS-in-JS (Why We're Breaking Up with CSS-in-JS). The numbers are specific to that codebase, but the direction is not.
- GitHub's Primer design system had its own
sxprop and has since removed it. Their engineering team cited "high runtime cost due to the dynamic nature of inline objects used forsx" and "difficulties scaling as the number of components usingsxon a page grew", and reported a 55% cut in server rendering time after moving to CSS Modules (GitHub Blog, Improving site performance by shipping more CSS). Primer v38 states plainly: "Thesxprop is no longer supported" (primer/react v38).
The Primer case is worth reading for a second reason: it took them months to migrate
thousands of sx props out. That is the bill for a styling habit, paid later.
It keeps you in client components
sx runs through Emotion, and Emotion needs React context, which only exists in
client components. The Next.js documentation lists MUI as supported in Client
Components (Next.js, CSS-in-JS), and
MUI's announcement of Pigment CSS named the same limit: "the React context API only
works with client-side components"
(MUI, Introducing Pigment CSS).
Pigment CSS was MUI's planned way out, compiling styles at build time. As of January
2026 it "remains in alpha phase and is currently on hold"
(MUI, 2026 and beyond). So sx in Material
UI today means Emotion at runtime, with no announced date for that to change. Styles
in plain CSS do not have this problem at all.
When sx is fine
To be fair to it: sx is theme-aware, and used with theme keys it does not bypass
your tokens. sx={{ color: "primary.main", p: 2 }} reads the palette and the spacing
scale. For a genuinely one-off adjustment, a single element on a single screen, it is
exactly what MUI built it for.
The trouble starts when it stops being one-off: raw pixel and hex values, the same
object copied to a second file, and sx as the default instead of the exception.
What to do instead
A simple rule for where styling goes, from broadest to narrowest:
- The theme and your tokens for anything that defines the product: colours, radius, spacing, typography.
- One stylesheet per component for the product's own look of each MUI
component, written against MUI's class names. We use CSS files with Tailwind's
@apply, in a cascade layer above MUI; the setup is in our post on MUI and Tailwind. - Variants for repeated differences: a
tinybutton size or acompacttable, declared once, used by name. - className or sx at the call site only for layout around the component and the true one-off.
Then make the rule visible. Count where you are today:
grep -rn "sx={" src | wc -land stop the number growing with a lint warning, using ESLint's built-in
no-restricted-syntax rule:
rules: {
"no-restricted-syntax": [
"warn",
{
selector: "JSXAttribute[name.name='sx']",
message: "Style in the theme or the component stylesheet. sx is for one-offs.",
},
],
},A warning, not an error: the point is that each new sx is a decision someone made
on purpose, not the path of least resistance.
For scale, our Gogo template source has about 14,000 className attributes and two
sx props. That is not purity. It is what happens when there is always a better
place to put the style.