Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MUI: cannot apply background color to Paper component

I’m trying to style the MUI <Paper> component, however setting the background color isn’t working. Following the online tutorials I’m applying the background-color CSS property to the root element of the Paper but the color remains white while other CSS properties – in this case padding and text-align work. Can someone please tell me what I am missing?

import React from 'react';  
import { Paper, Typography } from '@mui/material';
import { makeStyles } from '@mui/styles';
import AccessAlarmIcon from '@mui/icons-material/AccessAlarm';

const useStyles = makeStyles({
    root: {  
        textAlign: 'center',
        padding: 15,
        backgroundColor: '#37474f',
        }
    
});

export default function Header() {

    const classes = useStyles();

    return( 
        <Paper outlined square className={classes.root} 
        >
            <Typography variant="h2" component="h1"> 
                Pomodoro Cl
                <AccessAlarmIcon sx={{ fontSize: 45, color: 'red' }} />
                ck
            </Typography>
        </Paper>
    )
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

First of all your attribute outlined is incorrect, it should bevariant="outlined" as per the documentation.
For the background-color not working, you will need to add !important to the property so it takes precedence over mui’s default styling.
Here’s a working codesandbox for you: https://codesandbox.io/s/strange-smoke-y6yhv?file=/src/App.tsx

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading