Normally you would put them next to the component. Component.tsx component.module.css Answer from _AndyJessop on reddit.com
๐ŸŒ
Create React App
create-react-app.dev โ€บ docs โ€บ adding-a-css-modules-stylesheet
Adding a CSS Modules Stylesheet | Create React App
Learn more about CSS Modules here. ... import React, { Component } from 'react'; import styles from './Button.module.css'; // Import css modules stylesheet as styles import './another-stylesheet.css'; // Import regular stylesheet class Button extends Component { render() { // reference as a js object return <button className={styles.error}>Error Button</button>; } } Copy
๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_css_modules.asp
React CSS Modules
In React, CSS Modules are CSS files where class names are scoped locally by default.
Discussions

Real-world projects using CSS modules?
Normally you would put them next to the component. Component.tsx component.module.css More on reddit.com
๐ŸŒ r/reactjs
7
14
March 11, 2024
reactjs - How to apply global styles with CSS modules in a react app? - Stack Overflow
I'm currently using CSS Modules with React for my styling. So each of my components is importing in it's component specific css file, like so: import React from 'react'; import styles from './App.... More on stackoverflow.com
๐ŸŒ stackoverflow.com
CSS modules in react
By default Nextjs use "Component.module.css". The answer depends on your stack and file naming system. More on reddit.com
๐ŸŒ r/reactjs
7
4
March 28, 2022
reactjs - How to use css modules with create-react-app? - Stack Overflow
According to a tweet by Dan Abramov, CSS modules support is there in create-react-app (CRA). One just needs to give extension of module.css to his stylesheets to enable the feature, but this is not More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Medium
medium.com โ€บ @ralph1786 โ€บ using-css-modules-in-react-app-c2079eadbb87
Using CSS Modules In React App. Welcome back reader to another blogโ€ฆ | by Rafael Cruz | Medium
February 23, 2022 - CSS Modules is a great approach for making CSS locally scoped and for preventing naming clashes in medium to large projects. I hope you were able to gain a better understanding of how CSS Modules work, their benefits and how you can implement them into your React application.
๐ŸŒ
Adobe Developer
developer.adobe.com โ€บ commerce โ€บ pwa-studio โ€บ guides โ€บ general-concepts โ€บ css-modules
CSS modules
PWA Studio supports CSS modules out-of-the-box and using them is the recommended approach for styling components. React lets you split the UI into independent and reusable components, which allows you to update small parts of your UI without refreshing the page.
๐ŸŒ
GitHub
github.com โ€บ gajus โ€บ react-css-modules
GitHub - gajus/react-css-modules: Seamless mapping of class names to CSS modules inside of React components. ยท GitHub
If you are not familiar with CSS Modules, it is a concept of using a module bundler such as webpack to load CSS scoped to a particular document. CSS module loader will generate a unique name for each CSS class at the time of loading the CSS ...
Starred by 5.2K users
Forked by 214 users
Languages ย  JavaScript
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @gopi07it โ€บ css-modules-in-react-7f86b2e822ef
CSS Modules In React | Medium
January 1, 2025 - CSS Modules In React CSS Modules allow developers to write CSS styles that are scoped to specific components. Each component can have its own CSS file, ensuring that styles do not leak out and affect โ€ฆ
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
React CSS modules - Visual Studio Marketplace
Extension for Visual Studio Code - React CSS modules - VS code extension for CSS modules support in React projects written in typescript.Supports Definitions, Hover , Completion Providers and Diagnostics
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ react-css-modules
react-css-modules - npm
May 11, 2019 - Seamless mapping of class names to CSS modules inside of React components.. Latest version: 4.7.11, last published: 7 years ago. Start using react-css-modules in your project by running `npm i react-css-modules`. There are 324 other projects in the npm registry using react-css-modules.
      ยป npm install react-css-modules
    
Published ย  May 11, 2019
Version ย  4.7.11
Author ย  Gajus Kuizinas
๐ŸŒ
Docureacten
docureacten.github.io โ€บ css modules
CSS Modules | React.js: Learn Easily with Examples
CSS Modules are CSS files where all class and animation names are scoped locally by default. This means that when you import a CSS Module into a React component, the styles defined within that module only apply to that component.
๐ŸŒ
Testmuai
testmuai.com โ€บ testmu ai โ€บ blog โ€บ how to use css modules with react applications | testmu ai
How to Use CSS Modules With React Applications | TestMu AI (Formerly LambdaTest)
This demonstrates the power of CSS Module composition in action! As we are done creating the logic for navigation links and buttons, letโ€™s create the HeroSection and other necessary components. import React from 'react' import HeroImage from '../HeroImage/HeroImage' import HeroText from '../HeroText/HeroText' import styles from './HeroSection.module.css' export default function HeroSection() { return ( <section className={styles.section}> <HeroText /> <HeroImage /> </section> ) }
Published ย  January 13, 2026
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ reactjs โ€บ how-do-css-modules-help-in-styling-react-components
How do CSS Modules help in styling React components? - GeeksforGeeks
July 23, 2025 - CSS Modules help in styling React components by providing a way to create modular stylesheets where each component's styles are contained within its own module.
๐ŸŒ
Vite
vite.dev โ€บ guide โ€บ features
Features | Vite
Importing such a file will return the corresponding module object: ... CSS modules behavior can be configured via the css.modules option.
Top answer
1 of 11
126

You do not need to eject.

Create React App supports CSS Modules right out of the box as of version 2.

Upgrade to the latest (react-scripts@latest) version.

If you use yarn:

Copyyarn upgrade react-scripts@latest

If you use npm:

Copynpm install --save react-scripts@latest

Then you just have to create a file with the extension .module.css

For example:

Copy.myStyle {
  color: #fff
}

Then you can use it like so:

Copyimport React from 'react'
import styles from './mycssmodule.module.css'

export default () => <div className={styles.myStyle}>We are styled!</div>
2 of 11
11

To enable CSS module in to your app, you don't need to eject create-react-app. You can follow these simple steps described in this link to use CSS module in your project.

But in case if you ejected your create-react-app, then you must find file named

"webpack.config.js"

open this file and find this {test:cssRegex....etc} in line no. 391 and replace to this changes:

Copy            {
              test: cssRegex,
              exclude: cssModuleRegex,
              use: getStyleLoaders({
              importLoaders: 1,
              modules: true,
              localIdentName: '[name]__[local]__[hash:base64:5]'
            }),
            },

Open .js file and import statement like this

Copyimport cssStyleClassName from './MyApp.css';

Then this import statement allow you to do following changes in component tags like this

Copy<div className={cssStyleClassName.styleName}></div>

styleName is what you defined in your MyAppStyle.css file

Copy.styleName{
your properties here...
}

After eject your app, you must restart your local server, sometime changes don't get reflect.

Note In earlier version there were two generated file for production and dev separately. Now in current version one file named "webpack.config.js" file for which you need to concerned for changes. Thank you.

๐ŸŒ
CoreUI
coreui.io โ€บ answers โ€บ how-to-style-components-with-css-modules-in-react
How to style components with CSS modules in React ยท CoreUI
October 4, 2025 - Use CSS modules with .module.css extension and import class names for scoped component styling.
๐ŸŒ
Reddit
reddit.com โ€บ r/reactjs โ€บ react-css-modules (and derivatives/forks) vs css-modules
r/reactjs on Reddit: react-css-modules (and derivatives/forks) vs css-modules
January 21, 2025 -

Hi, there is a deprecated library that I have been using for my personal projects called react-css-modules. The maintainer created a babel plugin that has less performance overhead called babel-plugin-react-css-modules which is also not being maintained currently. Luckily, someone created a fork of the babel plugin and is maintaining it under dr.pogodin/babel-plugin-react-css-modules.

I like this CSS solution more than css-modules because it is easy to separate between the classes inside of your scoped CSS module and global classes and because you can configure it to tell you whether any of your classes are unused. You can even enforce the use of a single CSS modules per ReactElement.

This is really my favorite solution to CSS, at least when using React, yet this library does not seem to be used often in projects. If you use css-modules, why would you choose css-modules over one of these libraries? Is it because css-modules is actively maintained and has more tooling around it with plugins like typescript-plugin-css-modulesand typed-css-modules? Would you ever consider using these libraries, at least for personal projects? Is it really that bad of an idea to use unmaintained packages (react-css-modules or babel-plugin-react-css-modules) or maintained packages with a tiny group of contributors (dr.pogodin/babel-plugin-react-css-modules)? I do plan on perhaps open-sourcing a project I am building soon so I would use css-modules because it would be more familiar to contributors for the project.

Would it make sense to use the unmaintained, yet stable (in my experience) react-css-modules or babel-plugin-react-css-modules ever to make sure no bugs creep up in my projects instead of using a regularly maintained yet unknown package in dr.pogodin/babel-plugin-react-css-modules?

Thanks.

๐ŸŒ
Emotion
emotion.sh โ€บ docs โ€บ introduction
Emotion โ€“ Introduction
You simply prefer to use the css function to generate class names and cx to compose them. Server side rendering requires additional work to set up ... Hover to change color. ... The @emotion/react package requires React and is recommended for users of that framework if possible.
๐ŸŒ
GitHub
github.com โ€บ css-modules โ€บ css-modules
GitHub - css-modules/css-modules: Documentation about css-modules ยท GitHub
Solves Global Scope Problems: CSS Modules prevent the common issue of styles in one file affecting the entire project by localizing styles to specific components.
Starred by 18K users
Forked by 557 users