# Breaking changes in v5, part one: styles and themes

This is a reference guide to the breaking changes introduced in Material UI v5, and how to migrating from v4. This part covers changes to styling and theming.

## Material UI v5 migration 1. [Getting started](/material-ui/migration/migration-v4/) 2. Breaking changes part one: style and theme 👈 _you are here_ 3. [Breaking changes part two: components](/material-ui/migration/v5-component-changes/) 4. [Migrating from JSS](/material-ui/migration/migrating-from-jss/) 5. [Troubleshooting](/material-ui/migration/troubleshooting/) ## Breaking changes, part one Material UI v5 introduces a number of breaking changes from v4. Many of these changes can be resolved automatically using [the codemods](/material-ui/migration/migration-v4/#run-codemods) described in the [main migration guide](/material-ui/migration/migration-v4/). The following document lists all breaking changes related to styles and themes in v5 and how to address them. After you're finished here, please move on to [Breaking changes in v5 part two: components](/material-ui/migration/v5-component-changes/) to continue the migration process. :::warning Breaking changes that are handled by codemods are denoted by a ✅ emoji in the table of contents on the right side of the screen. If you have already followed the instructions in the main migration guide and run the codemods, then you should not need to take any further action on these items. All other changes must be handled manually. ::: ## Migrate theme styleOverrides to Emotion ### Refactor local rule references Although your style overrides defined in the theme may partially work, there is an important difference regarding how the nested elements are styled. The `$` syntax (local rule reference) used with JSS will not work with Emotion. You need to replace those selectors with a valid class selector. #### Replace state class names ```diff const theme = createTheme({ components: { MuiOutlinedInput: { styleOverrides: { root: { - '&$focused': { + '&.Mui-focused': { borderWidth: 1, } } } } } }); ``` #### Replace nested classes selectors with global class names ```diff const theme = createTheme({ components: { MuiOutlinedInput: { styleOverrides: { root: { - '& $notchedOutline': { + '& .MuiOutlinedInput-notchedOutline': { borderWidth: 1, } } } } } }); ``` :::info For each component, we export a `[component]Classes` constant that contains all nested classes for that component. You can rely on this instead of hardcoding the classes. ::: ```diff +import { outlinedInputClasses } from '@mui/material/OutlinedInput'; const theme = createTheme({ components: { MuiOutlinedInput: { styleOverrides: { root: { - '& $notchedOutline': { + [`& .${outlinedInputClasses.notchedOutline}`]: { borderWidth: 1, } } } } } }); ``` Take a look at the complete [list of global state classnames](/material-ui/customization/how-to-customize/#state-classes) available. ### Refactor alternative syntax for space- and comma-separated values The alternative, array-based syntax JSS supports for space- and comma-separated values is not supported by Emotion. #### Replace array-based values with string-based values **Before** ```jsx const theme = createTheme({ overrides: { MuiBox: { root: { background: [ ['url(image1.png)', 'no-repeat', 'top'], ['url(image2.png)', 'no-repeat', 'center'], '!important', ], }, }, }, }); ``` **After** ```jsx const theme = createTheme({ components: { MuiBox: { styleOverrides: { root: { background: 'url(image1.png) no-repeat top, url(image2.png) no-repeat center !important', }, }, }, }, }); ``` Be sure to add units to numeric values as appropriate. **Before** ```jsx const theme = createTheme({ overrides: { MuiOutlinedInput: { root: { padding: [[5, 8, 6]], }, }, }, }); ``` **After** ```jsx const theme = createTheme({ components: { MuiOutlinedInput: { styleOverrides: { root: { padding: '5px 8px 6px', }, }, }, }, }); ``` ## ref ### Refactor non-ref-forwarding class components Support for non-ref-forwarding class components in the `component` prop or as immediate `children` has been dropped. If you were using `unstable_createStrictModeTheme` or didn't see any warnings related to `findDOMNode` in `React.StrictMode` then you don't need to take any further action. Otherwise check out the [Caveat with refs](/material-ui/guides/composition/#caveat-with-refs) section in the Composition guide to find out how to migrate. This change affects almost all components where you're using the `component` prop or passing `children` to components that require `children` to be elements (for example ``). ### Fix ref type specificity For some components, you may get a type error when passing `ref`. To avoid the error, you should use a specific element type. For example, `Card` expects the type of `ref` to be `HTMLDivElement`, and `ListItem` expects its `ref` type to be `HTMLLIElement`. Here is an example: ```diff import * as React from 'react'; import Card from '@mui/material/Card'; import ListItem from '@mui/material/ListItem'; export default function SpecificRefType() { - const cardRef = React.useRef(null); + const cardRef = React.useRef(null); - const listItemRef = React.useRef(null); + const listItemRef = React.useRef(null); return (
); } ``` Here are the specific element types that each component expects: #### @mui/material - [Accordion](/material-ui/api/accordion/) - `HTMLDivElement` - [Alert](/material-ui/api/alert/) - `HTMLDivElement` - [Avatar](/material-ui/api/avatar/) - `HTMLDivElement` - [ButtonGroup](/material-ui/api/button-group/) - `HTMLDivElement` - [Card](/material-ui/api/card/) - `HTMLDivElement` - [Dialog](/material-ui/api/dialog/) - `HTMLDivElement` - [ImageList](/material-ui/api/image-list/) - `HTMLUListElement` - [List](/material-ui/api/list/) - `HTMLUListElement` - [Tab](/material-ui/api/tab/) - `HTMLDivElement` - [Tabs](/material-ui/api/tabs/) - `HTMLDivElement` - [ToggleButton](/material-ui/api/toggle-button/) - `HTMLButtonElement` #### @mui/lab - [Timeline](/material-ui/api/timeline/) - `HTMLUListElement` ## Style library ### ✅ Adjust CSS injection order The style library used by default in v5 is [Emotion](https://emotion.sh/docs/introduction). If you were using JSS for the style overrides of Material UI components—for example, those created by `makeStyles`—you will need to take care of the CSS injection order. JSS `' elements need to be injected in the `` after Emotion `