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!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

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

Okay