Set main and check contrastText: at the default threshold of 3, white text can read under 4.5:1

How to change Material UI theme colors

To change Material UI theme colors in Material UI v9, pass createTheme a palette with primary: { main } and secondary: { main } set to your hex codes, and wrap your application in a ThemeProvider. Material UI calculates light, dark and contrastText from each main color you provide. To choose hex codes before updating your codebase, load your deployed site into Recolor (recolor.page), press Space until a palette fits, and check the contrast of each swatch.

Last updated

Material UI's palette, theming, dark mode and CSS theme variables docs (v9.5.0) and its createPalette.js, read 14 Nov 2026, with a pick from Recolor's default palette
SettingWhat the docs sayA pick from the default palette
palette.primary.mainThe main shade of the primary color, the only token required#264653, white text at 10.08:1
palette.secondary.mainThe main shade of the secondary color#2a9d8f with contrastText: '#000', 6.32:1
light, dark and contrastTextCalculated from main when left out; tonalOffset, 0.2 by default, shifts the luminanceLeft to Material UI for primary
palette.contrastThreshold3 by default; the accessibility section sets 4.54.5
palette.error, warning, info and successThe other default palette colors#e76f51 as error, #f4a261 as warning
colorSchemes.dark.paletteThe dark scheme's tokens, preferred over palette since v6#e9c46a as the primary main
cssVariables: trueWrites the theme to :root as --mui-palette-primary-main and the restThe same hex codes, as variables

The palette in createTheme

Material UI uses a palette configuration inside createTheme to set up component colors. Material UI's palette docs (v9.5.0) give each color four tokens: main, light, dark and contrastText. Only main is required when you define a color. The tokens light and dark come from shifting main's luminance by tonalOffset, which is 0.2 by default.

The default palette colors are primary, secondary, error, warning, info and success. Material UI's theming docs say ThemeProvider must be a parent of the components it customizes. Customizing a theme with the default palette values looks like this:

jsx
import { createTheme, ThemeProvider } from '@mui/material/styles';

const theme = createTheme({
  palette: {
    primary: {
      main: '#264653',
    },
    secondary: {
      main: '#2a9d8f',
      contrastText: '#000',
    },
    warning: {
      main: '#f4a261',
    },
    error: {
      main: '#e76f51',
      contrastText: '#000',
    },
  },
});

function App() {
  return <ThemeProvider theme={theme}>...</ThemeProvider>;
}

Material UI's palette docs list hex, rgb and hsl as the supported formats. Modern color models like oklch require the native color feature.

Check contrastText yourself

You must verify contrastText manually because contrastThreshold defaults to 3 in Material UI. Material UI's createPalette.js (v9.5.0) gives a color white text whenever white reaches that threshold. White text on #2a9d8f reads 3.32:1 and on #e76f51 reads 3.09:1. Both ratios stay under 4.5:1, the WCAG AA level for normal text.

Black text reads 6.32:1 on #2a9d8f and 6.79:1 on #e76f51. For these two colors, the code sets contrastText: '#000' directly to ensure readable black or white text. In contrast, #264653 keeps white text at 10.08:1, and #f4a261 receives dark text automatically.

Material UI's theming docs note that the accessibility section sets contrastThreshold: 4.5 instead. The docs warn that raising the threshold can give counterproductive results across your palette, so check the APCA contrast too when testing colors:

JavaScript
import { createTheme } from '@mui/material/styles';

const theme = createTheme({
  palette: {
    contrastThreshold: 4.5,
    primary: {
      main: '#264653',
    },
    secondary: {
      main: '#2a9d8f',
    },
  },
});

Dark mode and CSS variables

Material UI uses colorSchemes to manage light and dark themes in modern releases. Material UI's dark mode docs state that since v6 the docs prefer colorSchemes to palette for light and dark. If you supply both options to createTheme, palette takes precedence.

Each color scheme accepts the same palette object structure:

JavaScript
const theme = createTheme({
  colorSchemes: {
    light: {
      palette: {
        primary: {
          main: '#264653',
        },
      },
    },
    dark: {
      palette: {
        primary: {
          main: '#e9c46a',
        },
      },
    },
  },
});

Material UI's CSS theme variables docs explain that setting cssVariables: true writes the theme to :root as variables such as --mui-palette-primary-main. Material UI's theming docs list community theme builders that preview a theme on Material UI's components. Recolor does not preview isolated components; Recolor shows the palette directly on your own pages.

Try the palette on your deployed site first

Testing palette colors on your live layout avoids unexpected color clashes before you touch your code. Paste your deployed address into Recolor and press Space to generate new combinations. When you find a shade you want to keep, lock that color with L.

Each swatch shows its contrast ratio with black and white text. To review relationships across background and foreground shades, the contrast matrix gives every pair. Recolor reads the page's CSS colors, variables included, to apply changes live.

An application drawn in the browser needs Scripts on. Module scripts from another domain often cannot start in the sandbox. A localhost address is refused by the service: deploy a preview or upload the saved page instead. Static assets like photos, video and canvas elements keep their colors during repaints.

No export from Recolor pastes into createTheme as it is. The JSON export gives a plain colors list, so copy each hex code into a main token by hand.

Common questions

Can I write Material UI palette colors in oklch?

No. The palette takes hex, rgb and hsl formats. Using oklch requires Material UI's native color feature.

Does Material UI's calculated contrastText always reach 4.5:1?

No. The default threshold is 3, so automatically assigned white text can read under 4.5:1 on medium backgrounds.

Does palette win when both palette and colorSchemes are set?

Yes. Material UI's dark mode docs state that palette takes precedence whenever both are defined.

Does Recolor's export paste into createTheme as it is?

No. Copy each hex code into a main property manually because the JSON export provides a plain list of colors.

Is it free?

Yes. Loading a site, generating palettes and every export format are free, without an account, as shown on the pricing page.

Sources