No more CSS, you say? Plot twist: it never left. It just changed its outfit (and not always for the best).

TL;DR

  • MUI components are HTML elements with a styling API attached. <Box> is a <div>, and the styles go into the sx prop.
  • Spacing-ish things are multiplied by 8, size-ish things are pixels, colours are names.
  • variant = how it looks. component = which HTML tag renders.
  • Theme for identity, sx for layout.
  • Anything marked (ours) is a rule of our project's theme, not a MUI default.

When we started working on Poolaki, a shared expense tracker we built as our 42 Berlin graduation project, I knew HTML and CSS reasonably well. I could centre a div (eventually). I knew what flex: 1 did.

The project required a styling library, so we looked at the usual suspects and picked MUI: a big, mature library with a lot of documentation, charts we knew we'd need for reports, and proper TypeScript support — every component comes typed, so the editor autocompletes props, catches a misspelled varient before the browser does, and even the theme can be typed with your own colours and text variants. Sensible choice on paper. Then I wrote my first real component, and it came out looking like this:

<Stack direction="row" spacing={2} sx={{ alignItems: "center", px: 3 }}> 

No <div>. No class names. A spacing={2} that was somehow 16 pixels. A px: 3 that was 24 of them. Where was my CSS? 🙃

It turned out the CSS was still there. It had just moved house. This post is the map I drew while finding it: every HTML tag and CSS property I kept reaching for, and what it became in MUI. Plus the handful of things that tripped me up, so they don't trip you.

A note on "ours": our project customises the MUI theme (radius, colours, custom text variants, breakpoints). Where something below comes from our theme and not from MUI itself, I mark it (ours), so you know what to expect in a fresh project.

First, the one idea that makes everything click

MUI components are HTML elements with a styling API attached. <Box> is a <div>. <Typography> is a <p> (or whatever you tell it to be). The difference is that instead of writing CSS in a separate file and pointing at it with a class, you hand the styles to the component through the sx prop:

// plain CSS <div className="card">…</div> .card { padding: 24px; border-radius: 16px; background: #fff; } // MUI <Box sx={{ p: 3, borderRadius: 2, bgcolor: "background.paper" }}>…</Box> 

Same CSS, three changes: the property names got shorter, the numbers got multiplied, and the colour became a name that comes from a theme. Once I understood those three changes, I could read any file in the project. So that's what the tables below are about.

Cheat sheet 1: tags → components

I wanted to write… In MUI it's… Notes
<div> <Box> A div with an sx prop. The workhorse.
<div style="display:flex"> <Stack> Flex container with a spacing prop for gaps. direction="row" for horizontal. I stopped writing display: flex by hand entirely.
<section>, <header>, <main>, <span> <Box component="section"> Any MUI component takes component= to change the rendered tag. Keeps the semantics, keeps the sx.
<p>, <h1>…<h6> <Typography variant="body1">, variant="h1" variant picks the look from the theme; component picks the tag. They're independent: <Typography variant="h2" component="h1"> is a thing, and it's correct.
<a href> <Link> For in-app navigation: <Link component={RouterLink} to="/x">. Never a bare <a> for internal routes, it reloads the page.
<button> <Button>, <IconButton> variant="contained" is the filled one, "outlined", "text". IconButton is round and takes an icon as its child.
<input>, <label> <TextField> Input + label + helper text + error state in one. label=, helperText=, error={bool}.
<input type="checkbox"> <Checkbox>, <Switch> Wrap in <FormControlLabel label="…"> to get the clickable label.
<select> <TextField select> + <MenuItem> Yes, a select is a TextField. Took me a while.
<table>, <tr>, <td> <Table>, <TableRow>, <TableCell> Same structure, inside <TableContainer>. align="right" on a cell for numbers.
<ul>, <li> <List>, <ListItem>, <ListItemButton> For navigation and menus. For data, a Stack of cards is often nicer.
a card / panel <Paper> A surface with a radius and (optionally) shadow. (ours) every card is <Paper variant="card">, the look lives in the theme.
a modal <Dialog> <DialogTitle>, <DialogContent>, <DialogActions> inside. open={bool}, onClose={fn}.
a slide-in panel <Drawer> anchor="right" or "bottom" (bottom = mobile sheet).
a little tag/pill <Chip> label=, onDelete= gives you the ×, size="small".
a tooltip <Tooltip title="…"> Wrap the element. Needs a child that can hold a ref, so wrap plain text in a <span>.
an alert box <Alert severity="error"> Also "success", "warning", "info".
tabs <Tabs value={…}> + <Tab value=… label=…> Controlled: you hold the value, onChange={(_, v) => …}.
a loading spinner <CircularProgress> Or <Skeleton> for placeholder shapes.
an icon import SearchIcon from "@mui/icons-material/Search" Per path, always. The barrel import pulls in 2000 icons and your dev server will hate you.

Cheat sheet 2: CSS properties → sx

The sx prop takes an object. Most keys are just camelCased CSS. A handful have shorthands and units, and those are the ones to memorise.

CSS sx What the value means
margin m number × 8px. m: 2 = 16px
margin-top / -bottom / -left / -right mt, mb, ml, mr same
margin-left + margin-right mx horizontal both sides
margin-top + margin-bottom my vertical both sides
padding and friends p, pt, pb, pl, pr, px, py same scale. px: 3 = 24px left and right
gap gap number × 8px too
width, height, min-width… width, height, minWidth… numbers are pixels, not × 8. width: 320 = 320px. Strings pass through: "100%". A value between 0 and 1 is a percentage: width: 0.5 = 50%
background-color bgcolor a theme path: "background.paper", "primary.light"
color color a theme path: "text.secondary", "error.main"
border-radius borderRadius number × the theme's base radius. MUI's default is 4px; (ours) is 8px, so here borderRadius: 2 = 16px (and 8px in a fresh project). 999 = pill
border border: 1 1 becomes 1px solid; set colour with borderColor: "divider"
font-size, font-weight fontSize, fontWeight fontSize: 14 = 14px; "0.875rem" passes through. Or set a whole variant: typography: "body2"
display, flex-direction, align-items, justify-content, flex-wrap, flex same, camelCased plain CSS, no magic
position, top, z-index, overflow, opacity, transition same, camelCased plain CSS
text-align, white-space, text-overflow textAlign, whiteSpace, textOverflow plain CSS
box-shadow boxShadow a string, or a number 0–24 for the theme's shadow levels
:hover "&:hover": { … } & = this element. Same for "&:focus-visible", "&.Mui-selected"
child selector "& .MuiButton-startIcon": { … } reach into MUI's own class names when you must
@media (min-width: 600px) { xs: …, sm: … } or [TABLET]: { … } see breakpoints below

The pattern behind the units: spacing-ish things are multiplied by 8, size-ish things are pixels, colours are names. Once that stuck, I stopped guessing.

Cheat sheet 3: colours, text, breakpoints

Colours are names, not hex

// ❌ what I did at first sx={{ color: "#959698" }} // ✅ what we settled on sx={{ color: "text.secondary" }} 

The theme (theme.ts) defines primary, secondary, success, error, text, background and divider. Each colour has .main, .light, .dark. (ours): we use success for income and error for expenses, and we added our own accent. When the designer changes a colour, one line changes, not forty files. I now flinch when I see a hex code in a component.

Typography variants are the font scale

I'd have written… Variant
a page title h1, h2 (ours: h2 for page titles, rendered as an <h1> tag. Look vs. semantics again)
a card title h3
body text body1 (default)
secondary / smaller text body2
tiny caption caption
UPPERCASE LABELS label (ours, a custom variant for table heads)
numbers mono (ours, for amounts in a monospace font)

Breakpoints

MUI's built-in names are xs (0), sm (600), md (900), lg (1200), xl (1536), and they work mobile-first: a value applies from that width up:

sx={{ display: { xs: "none", md: "block" } }} // hidden below 900px 

(ours): the project defines its own in lib/layout.ts, because the layout changes at 600, 980 and 1024, not 900 and 1200:

sx={{ px: 2, [TABLET]: { px: 3 } }} 

Same idea, the key is a media query, with different numbers. Either way: never a pixel value in a component. Named breakpoints only.

Cheat sheet 4: where does a style go?

This was the question I got wrong the longest. There are three places, and the rule turned out to be simple:

If the style is… Put it in… Example
what every instance of a component looks like theme.components in theme.ts "all buttons are pills", "all cards have a 24px radius"
a look shared by a few siblings a styles.ts next to them exporting an sx object tintedWhenActive(active) for the filter buttons
where this instance sits: margin, width, flex sx on the instance sx={{ mt: 2, flex: 1 }}

Theme for identity, sx for layout. If I'm about to paste the same sx for the third time, it's identity, and it belongs in the theme.

The demons that got me

Demon level = how much time it cost me. 💀 = a minute. 💀💀💀💀💀 = I lost an afternoon.

💀💀 borderRadius: 16 is not 16px. It's 16 × the base radius (8 in our theme), so 128px. I made a lot of very round things before I understood the multiplier. borderRadius: 2 is 16px here. For a pill, 999.

💀 width: 2 is 2px. The spacing multiplier applies to margin, padding and gap, not to sizes. Mixed those up for a week.

💀 Buttons shout by default. MUI uppercases button text. (ours) the theme sets textTransform: "none" once, globally. In a fresh project, if your buttons are SHOUTING, that's why.

💀💀 variant and component are different props. variant = how it looks (from the theme). component = which HTML tag renders. <Typography variant="h2" component="h1"> looks like our h2 style and is a real <h1> for screen readers. Use both.

💀💀 Paper has a shadow by default, and ours doesn't. (ours) the theme sets elevation: 0 everywhere so the app is flat; cards get a soft custom shadow through variant="card". If you add elevation={3} you'll get Material's shadow, which looks like it's from a different app.

💀💀 Stack kills your gap and margin tricks. It handles spacing itself through spacing={n}. Fighting it with mb on children makes a mess. Let it do its job.

💀💀💀 Icons: one import per icon. import AddIcon from "@mui/icons-material/Add". The tempting import { Add } from "@mui/icons-material" loads the whole library and your dev server reoptimises for a full minute. Ask me how I know.

💀 sx arrays merge. sx={[baseSx, cond && extraSx, props.sx]}: falsy entries are skipped. This is how a component can take an sx prop from its parent and still have its own. Not a demon, more of a friendly ghost.

💀💀💀 The theme is typed. Add a custom colour or variant and TypeScript complains until you tell it (declare module "@mui/material/styles"). Annoying for ten minutes, then you get autocomplete for your own tokens forever. Worth it.

The outfit isn't always flattering

I promised "not always for the best", so here's the other side. MUI did make me faster once I'd learned it. But the move from .css files into sx objects has a price, and it's fair to name it.

You lose the file. With plain CSS there is a stylesheet you can open and read top to bottom: every rule for the page, in one place, in one language. With sx, the same styles are spread across seven hundred little objects in seven hundred components. There's no single view of "what does this page look like". You read it one component at a time, or you don't read it at all.

The units lie a little. padding: 24px means 24px. p: 3 means 24px if you know the multiplier, and borderRadius: 3 means something else entirely because it has a different multiplier, and width: 3 means 3px because it has none. It's consistent once you know the rules, but it's a layer of rules on top of CSS, not instead of it. Plain CSS doesn't make you remember which properties are secretly multiplied.

Overriding means reading someone else's DOM. When the theme can't reach something, you end up writing "& .MuiButton-startIcon": { m: 0 } — a selector into markup you didn't write and can't see without opening the dev tools. Every one of those is a tiny bet that MUI won't rename the class in the next major version.

The cascade is gone, and I miss it sometimes. CSS was designed so that a rule on .card applies to every card, and a rule on .card.urgent refines it. With sx on instances, there is no refinement, only repetition — which is exactly why the project has the rule "third time in sx, move it to the theme". The rule exists because the tool took away the thing that used to handle this for free.

Would I pick it again? Depends on the project. For a dashboard with forms, tables and charts, where we needed a lot of components fast, it earned its place. For something smaller, or something with a strong design of its own, I'd think twice: modern CSS with variables and nesting gets you surprisingly far, and you keep the file. Either way, I'd use MUI with my eyes open: theme as much as possible, sx as little as possible, and no illusions that I've stopped writing CSS. I've just started writing it in a stricter dialect.

What I actually learned

Not MUI, really. What I learned is that a styling library is a vocabulary, and the hard part isn't the vocabulary, it's agreeing where each sentence goes. We didn't have that agreement on day one; we had a library and a lot of sx. The rules came out of the mess, one repeated style at a time: tokens in the theme, identity in the theme, layout in sx, breakpoints by name. Once we had them written down and I started reading components as "MUI element + a little sx for position", everything got faster. I could open a file I'd never seen and know what it would look like.

The cheat sheet above is the vocabulary. The rule, theme for identity and sx for layout, is the grammar. Learn the grammar first; the vocabulary you can look up. (That's what this post is for. 💜)