Lesson Three: Managing Styles in Next.js
Design plays a huge role in engaging users. In this lesson, we will explore different ways to manage styles in Next.js.
Next js tutorial
February 24, 2025

Lesson Three: Managing Styles in Next.js
Introduction
In modern applications, design plays a major role in attracting users. In this lesson, we’ll explore different ways to manage styles in Next.js, including:
- Adding global CSS files .
- Using CSS Modules for local styles.
- Adding Styling Libraries like Tailwind CSS or Material-UI.
1. Adding a Global CSS File
Next.js allows you to add a global CSS file that applies to your entire application. This file can contain basic styles that are applied across all pages.
Steps:
1.1 Creating a Global CSS File
- Open the styles/ folder in your project.
- Create a new file named global.css .
1.2 Adding Styles to the File
Add some simple styles to global.css :
1.3 Linking the File to the Application
To ensure these styles are applied to all pages, link the file in the _app.js component.
- Open the _app.js file located in the pages/ folder.
- Import the global.css file:
2. Using CSS Modules for Local Styles
CSS Modules is a tool that allows you to write styles specific to each component separately, preventing naming conflicts between styles.
Steps:
2.1 Creating a CSS Module
- Open the about.js file located in the pages/ folder.
- Create a new file named about.module.css next to the about.js file.
2.2 Adding Styles to the File
Add the following styles to about.module.css :
2.3 Importing and Using the Styles
Modify the about.js file to use the styles:
3. Adding a Styling Library (Example: Tailwind CSS)
Tailwind CSS is a popular styling framework that provides ready-to-use CSS classes you can apply directly in your HTML.
Steps:
3.1 Installing Tailwind CSS
In the Terminal, install Tailwind CSS using the following command:
3.2 Creating Tailwind Configuration Files
Create configuration files using the following command:
3.3 Modifying the tailwind.config.js File
Ensure the tailwind.config.js file contains the following settings:
3.4 Adding Tailwind to the CSS File
Open the global.css file and add the following code:
3.5 Using Tailwind in a Page
Modify the index.js file to use Tailwind:
4. Testing the Styles
After completing the above steps, run the project using:
npm run dev
Open your browser and go to http://localhost:3000 . You will notice that the styles have been successfully applied.
5. Comparison of Different Approaches
Conclusion of Lesson Three
In this lesson, you learned how to:
- Add a global CSS file to your application.
- Use CSS Modules to manage local styles.
- Add a styling library like Tailwind CSS.
In the next lesson, we’ll discuss managing data using getStaticProps and getServerSideProps .
See you in Lesson Four! 🚀
Comments

There are no comments
Please login to leave a review