DEV Community

Cassidy Williams for Netlify

Posted on • Originally published at netlify.com on

5 5

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!

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay