Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SX prop classes overridden by MUI theme

I am trying to style a component using the sx MUI prop.

<Typography
        variant='h1'
        align='center'
        sx={{ fontSize: '24px', pb: '8px', fontWeight: '700' }}
    >
        Admin Panel
</Typography>

The problem is: classes from MUI theme have more CSS specificity and override those from sx prop.

Here is MUI theme setup for typography:

typography: {
        h1: {
            fontSize: '2rem',
            '@media screen and (min-width: 768px)': {
                fontSize: '3rem',
            },
            '@media screen and (min-width: 1024px)': {
                fontSize: '3.5rem',
            },
        },
    },

Here is also how it looks in dev tools:enter image description here

Is this expected behavior? Is there any way I can solve this?

like image 434
Svyatoslav Logvinenko Avatar asked Jan 30 '26 11:01

Svyatoslav Logvinenko


1 Answers

It is expected that styles from your theme have more specificity. the selector's weight of @media screen and (min-width: 768px) .root' is bigger than just of .root. Either add an !important to your sx prop (what is not actually recommended) or add the @media sreen... to your sx styles as well

like image 61
Entity Avatar answered Feb 01 '26 03:02

Entity



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!