LogoLogo
HomeGitHubPlayground
v4
v4
  • ๐Ÿ”งSetup
  • ๐Ÿ”API References
    • tss - the Modern API
    • keyframes
    • <GlobalStyles />
    • makeStyles -> useStyles
    • withStyles
  • โšกSSR
    • Next.js
    • Gatsby
    • Other backends
  • ๐ŸŽฏIncrease specificity
  • ๐Ÿฆฑclasses overrides
  • ๐ŸงนDetecting unused classes
  • ๐Ÿ’ฝEmotion Cache
  • ๐Ÿ’ซNested selectors (ex $ syntax)
  • ๐ŸญMUI Global styleOverrides
  • ๐Ÿ“ฆPublish a module that uses TSS
  • ๐ŸฉณMUI sx syntax
  • ๐Ÿ“ฒReact Native
  • ๐Ÿ†˜Fix broken styles after upgrading to MUI v5 with TSS
  • โฌ†๏ธMigration v3 -> v4
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. API References

<GlobalStyles />

PreviouskeyframesNextmakeStyles -> useStyles

Last updated 1 year ago

Was this helpful?

Sometimes you might want to insert global css. You can use the <GlobalStyles /> component to do this.

It's styles (with an s) prop should be of same type as the function argument or you can use string interpolation (see below).

import { GlobalStyles } from "tss-react";
import { useStyles } from "tss-react/mui";

function MyComponent() {

    const { theme } = useStyles();

    return (
        <>
            <GlobalStyles
                styles={{
                    body: {
                        backgroundColor: theme.palette.background.default,
                    },
                    ".foo": {
                        color: "cyan"
                    },
                }}
            />
            <h1 className="foo">This text will be cyan</h1>
        </>
    );
}

Use string interpolation, for example to import font face:

<GlobalStyles
  styles={`
    @import url(${typography.fontFace.import});
  `}
/>

Is there a reason to use this instead of import GlobalStyles from "@mui/material/GlobalStyles";?

๐Ÿ”
css()
No