DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 968,547 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cassidy Williams for Netlify

Posted on • Originally published at netlify.com on

Global Styles in Next.js

Welcome to Blogvent, day 9!

In Next.js, you have TONS of support for pretty much every styling option you’d like to use. CSS Modules, Styled JSX, Sass, Less, Stylus, Styled Components, Emotion… I could go on! If you want to style a component, Next.js has you covered.

One thing that often trips people up though is adding global styles. But luckily, the framework has you covered there, too!

In your pages/ directory, add an _app.js file if you don’t already have one. Yours might look something like this:

// pages/_app.js

function Application({ Component, pageProps }) {
  return <Component {...pageProps} />
}

export default Application
Enter fullscreen mode Exit fullscreen mode

Now, to add some simple global styles to your application, it’s as simple as importing it at this level!

import '../styles/globals.css'

function Application({ Component, pageProps }) {
  return <Component {...pageProps} />
}

export default Application
Enter fullscreen mode Exit fullscreen mode

It’s done!

You now have a global stylesheet applied to your Next.js application. If you’d like to see it in a starter application, you can check out this repo here, or deploy the starter directly to Netlify with one click:

Deploy to Netlify

If you’d like to see this applied in a more advanced application, you can check out the repo for Jamstack Explorers!

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.