avatarRajdeep Singh

Summary

The provided web content is a guide on how to add CSS in Next.js projects, detailing the use of global stylesheets and CSS modules, along with setup instructions and resources for further learning.

Abstract

The article is part of a series on Next.js and focuses on the integration of CSS within Next.js projects. It introduces Next.js as a JavaScript framework that simplifies web development and highlights the new feature in version 9.3, which supports global CSS stylesheets and CSS modules for component-level styling. The author, Rajdeep Singh, explains the installation process of the @zeit/next-css package and the configuration required to import CSS files globally or locally using .module.css. The article also provides a demonstration through a CodeSandbox embed and encourages readers to engage with the author for feedback and to explore an AI service recommendation.

Opinions

  • The author, Rajdeep Singh, expresses enthusiasm about the ease of adding CSS in Next.js, indicating that the framework's custom CSS functionality is "Good News."
  • Singh emphasizes the importance of reading the basic introduction to Next.js to understand the framework's capabilities fully.
  • The author suggests that using the @zeit/next-css package and following the provided configuration steps will result in a seamless integration of CSS in Next.js projects.
  • Singh encourages readers to try out the AI service he recommends, implying that it is a cost-effective alternative to ChatGPT Plus (GPT-4) with similar performance and features.
  • The inclusion of a personal "About Me" section and contact information suggests that Singh values community engagement and is open to feedback and further discussion on the topic.

#Next.js

How To Add CSS In Next.js?

Easy Ways Add CSS in Next.js #SeriesPart2 💕

In this Next Series, we Learn How to add CSS Projects with Easy Steps.

Good News is that Next.js provides custom CSS functionality. You Use The next.js plugin inside your project and use it.

Add CSS in Next.js #SeriesPart2 💕

What Is Next.js?

Make sure to Read the Basic Introduction About Next.js #SeriesStart 💕

New Update:

Next.js Version 9.3 Support CSS Global Stylesheets. Now you add CSS directly. Import .css files as global stylesheets.

import './style.css'

Next.js Version 9.3 Support CSS Module for Component-Level Styles Now You Add import CSS use .module.css for local scope

import style from 'style.module.css'

Go To Github Download or Use Npm:

npm install --save @zeit/next-css
or
yarn add @zeit/next-css

Create a next.config.js in the root of your project.

Default:

default config used for importing CSS Global stylesheet in custom _app.js

const withCSS = require('@zeit/next-css')
module.exports = withCSS({})

Custom:

Custom config is used to import CSS in other Components like header and footer.

const withCSS = require('@zeit/next-css')
module.exports = withCSS({
cssModules: true  // After true than use import statement in next.js
})

How To add Global CSS:

When you install and create an app, use this npm command.

npx create-next-app myapp
# or
yarn create next-app myapp

In that case, the global custom _app.js creates by default in your project; otherwise, you create Global in your project to import your Global CSS file in next.js.

import '../styles.css'
or
import '../styles.scss'
// This default export is required in a new `pages/_app.js` file.
export default function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

Demo:

About Me

My Name is Rajdeep Singh. I’m a Front-end Developer, blogger, and A student in BioTechNology in Medical Science.

Reference:

Contact me:

Would you mind giving me feedback?
Nextjs
Reactjs
React
React Framework
React Tutorial
Recommended from ReadMedium