custom theme background color

Gerard López Sorribas picture Gerard López Sorribas · Jan 10, 2018 · Viewed 12.5k times · Source

I have material-ui@next installed and i want to customized the background color of the theme.

I tried this:

const theme = createMuiTheme({
  palette: createPalette({
    type: 'light',
    primary: purple,
    background: {
      default: '#303030',
    },
  }),
});

And this.

<MuiThemeProvider theme={theme}>

But the background color is still white when it should change to red.

Answer

knro picture knro · May 6, 2018

I also faced this issue. To fix this, import CssBaseline:

import CssBaseline from "@material-ui/core/CssBaseline";

Then add it like this:

<MuiThemeProvider theme={theme}>
    <CssBaseline />

Using CssBaseline while setting background color as follows the color gets applied:

import { createMuiTheme } from "@material-ui/core/styles";

const theme = createMuiTheme({
  palette: {
    background: {
      default: "#303030"
    }
  }
});

You can find a working snippet here.