question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot change the body background via theme configuration

See original GitHub issue

A question / suggestion or a potential bug.

I’m trying to configure a theme and when I try to change the background color the change does not get applied.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

With this theme configuration, I’m expecting the body background color to be #ff0000 but it’s actually #cccccc.

export default {
  palette: {
    type: 'light',
    primary: {
      main: '#00AAE1',
      dark: '#143C8C',
      contrastText: '#fff',
    },
    secondary: {
      main: '#64B42D',
      dark: '#008732',
      contrastText: '#fff',
    },
    error: {
      main: '#BD0043',
      contrastText: '#fff',
    },
    divider: '#D7D6D5',
    background: {
      paper: '#fff',
      default: "#ff0000"
    },
  },

  typography: {
    // Use the system font over Roboto.
    fontFamily: 'Avenir Next, Roboto,"Helvetica Neue",Arial,sans-serif',
    htmlFontSize: 16,
  },
};

const theme = createMuiTheme(uiThemeConfig);

Current Behavior

The body’s background color remains unchanged.

Steps to Reproduce (for bugs)

I found that having the <CssBaseline /> makes the background color possible. https://codesandbox.io/s/kkpw0y1vm5

But without it doesn’t work. https://codesandbox.io/s/q4kvw1kj4q

I must have missed this in the documentation to be a mandatory part of the setup. If so, then please point me to it 😃

Your Environment

Tech Version
Material-UI 1.0.0-beta.38
React 16.2.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:26 (15 by maintainers)

github_iconTop GitHub Comments

72reactions
nik-johncommented, Aug 31, 2018

I ran into this issue and eventually realized that I was wrapping <CssBaseline> around the <MuiThemeProvider> and not the other way around. This was causing <CssBaseline> to not be aware of the theme configuration.

KO 🔴

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

OK ✅

<MuiThemeProvider theme={muiTheme}>
  <CssBaseline />
  <App />
</MuiThemeProvider>
25reactions
oliviertassinaricommented, Mar 22, 2018

For reference, the CssBaseline documentation page.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot change the body background via theme configuration
I'm trying to configure a theme and when I try to change the background color the change does not get applied. @mnemanja It's...
Read more >
can't change body background color using CSS reset
Your CSS reset file sets the background color of html which is the entire page. You are only setting the body 's background...
Read more >
Topic: Can't change background color of “body” in Neat
Looking at the theme, it appears that the body background is really an image (blue gradient) and not really a background-color.
Read more >
I can't change the body background-color through style.css
It sounds like you just need to remove support for the custom background color. remove_theme_support( 'custom-background' );.
Read more >
How To Change Entire Page Body Background Color In ...
In today's video tutorial we'll learn how to change the entire page body background color using Elementor WordPress plugin in a simple, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found