To create global styles we can use createGlobalStyle function. For next.js project, you can do that in _app.js or _app.tsx file, depending on whether you are using typescript.

import type { AppProps } from "next/app";
import { createGlobalStyle } from "styled-components";

import Header from "@/components/Header";

const GlobalStyles = createGlobalStyle`
html,
body {
    padding: 0;
    margin: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

* {
    box-sizing: border-box;
}
`;

export default function MyApp({ Component, pageProps }: AppProps) {
  return (
    <>
      <GlobalStyles />
      <Header></Header>
      <Component {...pageProps} />
    </>
  );
}

Of course, if you have more global styles you can export the GlobalStyles from other file, say globalStyle.js.

But then there is nothing out there that stops you from using CSS or SCSS for your global styles. You can always import the .css or .scss or any other supported CSS preprocessor file types as you would normally do.

import '@/styles/global.scss'

And this would work perfectly fine with your Styled Components as well. Though there is a little advantage you get by using createGlobalStyle. You can use all SCSS features without having to add SCSS dependency in your project. And a little drawback is that the auto-complete features of the ide don't work as well with styled-components as they do with .css and .scss files.

Answer from Mayank Kumar Chaudhari on Stack Overflow
🌐
styled-components
styled-components.com › docs › api
styled-components
Returns a StyledComponent that does not accept children. Place it at the top of your React tree and the global styles will be injected when the component is "rendered".
Discussions

Do you guys create global Styled Components and just import them in your components/pages?
Depends. If you find yourself copying and pasting your own code you probably should look to make it more reusable. With MUI's sx and useTheme you can define all sorts of styles for components so that the styles aren't restricted to just a container. More on reddit.com
🌐 r/react
5
2
July 24, 2022
What’re the benefits of using styled components or css-in-js over importing a global css file?

I really like that styled components lets me have each bit of styling attached to specific components. I find it easier to reason about components with this as opposed to having to reference separate CSS files.

I think if you haven't used it before then it's completely understandable that it would seem counterintuitive.

More on reddit.com
🌐 r/nextjs
14
12
October 8, 2020
CreateGlobalStyles Rendered After Component Styles
I believe they should be rendered in the style tag first, before all component styles. Loading it last, would cause its rules to overwrite component rules (see highlighted .cooVxd rules). If we follow ITCSS rules (which is a pretty good rule) global rules should be overwritten by component rules. More on github.com
🌐 github.com
32
May 19, 2020
Why Tailwindcss over styled-components?
styled-components co-creator here — I wrote about why I love Tailwind myself: https://mxstbr.com/thoughts/tailwind More on reddit.com
🌐 r/reactjs
146
145
November 24, 2022
🌐
GitHub
github.com › styled-components › styled-components › issues › 2387
Global styles best practices or accessing generated classNames from styled components · Issue #2387 · styled-components/styled-components
February 15, 2019 - isn't working because sometimes there are more than one class appended to the styles. i don't even know exactly whats happening here, but i think it has something to do with https://www.styled-components.com/docs/faqs#why-do-my-dom-nodes-have-two-classes · appending the css to global with createGlobalStyle
Published   Feb 15, 2019
🌐
egghead.io
egghead.io › lessons › javascript-creating-global-styles-with-styled-components
Creating Global Styles with Styled Components | egghead.io
We will create global styles that apply to the whole document using the styled-components library. We create a global style using the createGlobalStyle...
🌐
Scalablecss
scalablecss.com › styled-components-global-styles
How to Create Global Styles with Styled Components - Scalable CSS
June 2, 2020 - Inside your src/ folder, add a file called globalStyles.js. Here, we’ll use the createGlobalStyle function from styled-components and add some global styles:
Find elsewhere
🌐
Dilshankelsen
dilshankelsen.com › create-global-styles-with-styled-components
How To Create Global Styles With Styled Components | Dilshan Kelsen
June 24, 2021 - Since GlobalCSS is a styled component 💅, it can also take advantage of ThemeProvider.
🌐
Gatsby
gatsbyjs.com › documentation › how-to guides › styling › using styled components
Styled Components | Gatsby
Styled-components are primarily used for a single CSS class that is isolated from other components. In some cases, you want to override global styling — for example, the default margins of your body element.
🌐
Smashing Magazine
smashingmagazine.com › 2020 › 07 › styled-components-react
How To Use Styled-Components In React — Smashing Magazine
July 23, 2020 - While the original goal of CSS-in-JS and, by extension, styled components is scoping of styles, we can also leverage styled components’ global styling. Because we’re mostly working with scoped styles, you might think that’s an invariable factory setting, but you’d be wrong.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › global-styling-with-styled-components-in-react
Global Styling with styled-components in React - GeeksforGeeks
July 23, 2025 - It uses tagged template literals ... modularity and reusability. Global Styling: Use GlobalStyle from styled-components to set global styles for body margin, color, and font-family....
🌐
DEV Community
dev.to › elijahtrillionz › complete-guide-on-how-to-use-styled-components-in-react-360c
Complete Guide On How To Use Styled-components In React - DEV Community
February 19, 2022 - Oftentimes, we have styles that need to be applied globally to avoid repetition, for example, you could want that all elements should be a border-box, rather than repeating it over and over for each element, we would say in CSS ... Another example could be removing all underline from a tags, applying different specific font-family on p and h1-h6 tags, or applying a custom scrollbar for your web pages, and many others. To apply these styles in styled-components is simple, we simply create a GlobalStyles styled component and apply it to our app once.
🌐
GitHub
github.com › styled-components › styled-components › issues › 2288
Request: use :global or :local similar to css-modules · Issue #2288 · styled-components/styled-components
However, declaring rules & .indirectly {} will cause a problem if a top-level component also defines rules for a component of the same name. I like how this is handled with css-modules where by default, all classes are :local, and you can opt out by using :global, or vise versa depending on your configuration. Ideally, there is a babel plugin or a webpack plugin that will preprocess files that use styled()().
🌐
Medium
medium.com › @navneetskahlon › styling-react-components-with-styled-components-a-powerful-approach-for-global-and-component-level-1d8520a33ca7
Styling React Components with Styled-Components: A Powerful Approach for Global and Component-Level Styles | by Navneet Singh | Medium
June 27, 2023 - Styled-components provides an elegant and flexible way to style React components by combining CSS and JavaScript in a single component. We explored how to use styled-components for managing global styles using the createGlobalStyle function ...
🌐
Medium
medium.com › @aimanwaseem.aw26 › styled-components-in-react-a-powerful-styling-solution-9d63f36f49c5
Styled-Components in React: A Powerful Styling Solution | by Aimanwaseem | Medium
June 14, 2023 - styled-components allows defining global styles using the createGlobalStyle API. This helps in applying styles to the entire application.
🌐
DEV Community
dev.to › marizoo › a-simple-global-styling-method-with-styled-component-1if6
A simple global styling method with styled component. - DEV Community
February 15, 2022 - import { css } from "styled-components"; // Create global color export const ctaColor = () => { return css` palevioletred `; }; // Create media queries export const mobile = (props) => { return css` @media (min-width: 576px) { ${props} } `; };
🌐
Reddit
reddit.com › r/nextjs › what’re the benefits of using styled components or css-in-js over importing a global css file?
r/nextjs on Reddit: What’re the benefits of using styled components or css-in-js over importing a global css file?
October 8, 2020 -

Reading through the Next.js docs doesn’t really mention any performance perks. Only benefit they mention really is that you don’t have to worry about class naming conflicts.

Aside from that, is using a global css file bad practice?

It feels more natural assigning class names and ID names then referencing them via a global style sheet that’s imported once rather than separating out the styling for each component.

What am I missing?

Top answer
1 of 7
7

I really like that styled components lets me have each bit of styling attached to specific components. I find it easier to reason about components with this as opposed to having to reference separate CSS files.

I think if you haven't used it before then it's completely understandable that it would seem counterintuitive.

2 of 7
7

My personal favourite styling option (especially with Next) is Tailwind.

I find it to be the best of both worlds. I did like styled-components when I first tried it, but I realized it just creates a lot of extra lines of code, and forces me to spend a bunch of time coming up with names for components. Container, ContentContainer, ContentContainerWrapper, etc.

And when I spend so much time writing the same things over and over:

display: flex;
align-items: center;
justify-content: center;

it makes way more sense (to me) to just extract those common styles to a utility class and just write:

<div className="flex items-center justify-center" />

instead of:

const WrapperDiv = styled.div`
    display: flex;
    align-items: center;
    justify-content: center;
`;

...

<WrapperDiv />

And that's not even to mention the life-changing other things Tailwind can do!

  • breakpoint utility classes, flex md:flex-row lg:flex-col

  • font sizes / spacing / color token management: text-sm text-green-100 p-5 m-2

And all super easily customizable to fit a design system in the Tailwind config file at the root of the repo.

Anyway, just wanted to mention Tailwind in this discussion because I've been obsessed with Tailwind + Next lately. I've never felt so productive as a frontend developer as when I'm using this stack.

But for when you do need more custom stuff that wouldn't be covered by Tailwind classes (which is a lot less than I thought it would be), I still haven't figured out my favourite option there. The css prop method is pretty cool though, and I like that it keeps your styles "with" the component.

🌐
CodeSandbox
codesandbox.io › s › styled-components-creating-global-styles-rnjmk
Styled Components - Creating Global Styles - CodeSandbox
December 12, 2019 - Styled Components - Creating Global Styles by FreedomWriter using react, react-dom, react-scripts, styled-components
Published   Dec 12, 2019
Author   FreedomWriter
🌐
Emotion
emotion.sh › docs › globals
Emotion – Global Styles
Sometimes you might want to insert global css like resets or font faces. You can use the Global component to do this. It accepts a styles prop which accepts the same values as the css prop except it inserts styles globally.
🌐
GitHub
github.com › styled-components › styled-components › issues › 3146
CreateGlobalStyles Rendered After Component Styles · Issue #3146 · styled-components/styled-components
May 19, 2020 - /* Component styles */ .cooVxd { padding-left: 15px; padding-right: var(--test); /* Trimmed */ } .fDNorw { padding-left: 15px; /* Trimmed */ } /* createGlobalStyle */ html { background-color: gray; } .cooVxd { padding-left: 50px; } body { background-color: yellow; }
Published   May 19, 2020
Author   pxwee5