Styles from a .module.css or .module.scss file do not reach the element
Your error
className="title" has no effect once the stylesheet is called Card.module.scss2 more lines it can showFix it fast
Most common cause, 1 of 4The stylesheet is a CSS Module but the JSX uses a plain string
Import the module as an object and read each class from it.
import styles from './Card.module.scss';
export function Card({ children }) {
return <div className={styles.title}>{children}</div>;
}Short answer
A className with no effect next to a .module.css or .module.scss file is a CSS Modules naming issue: each class gets a unique generated name that you read from the imported object, so a plain string matches nothing. Use styles.name, keep .module in the file name, brackets for hyphens and :global() for library classes. Vite 8, Next.js 16, React 19.3.
Which cause do you have?
Look at two things side by side: the exact file name of the stylesheet and the line that imports it. Whether the name has .module and whether you import an object decides which cause below applies.
ls src/components | grep -E "\.(css|scss)$"
grep -n -E "import .*\.(css|scss)" src/components/Card.jsxThen find the line you see in this list and open its fix:
- 1The stylesheet is a CSS Module but the JSX uses a plain string
The element carries class="title", while the rule that loaded has a longer, generated name - 2The file name has no .module part
The component does import styles from './Card.scss' (or .css) and reads styles.title - 3A hyphenated class name is read with a dot
The CSS has .card-title, and the JSX says styles.card-title - 4The rule targets a class the module did not create
The selector names a class that comes from a library or from a plain string, for example .swiper-slide inside Gallery.module.css
What does the error look like?
className="title" has no effect once the stylesheet is called Card.module.scssDevTools shows the class on the element, but no rule in the Styles pane matches itA rule for a library's class, written in a .module.css file, never applies
Cause 1 of 4
The stylesheet is a CSS Module but the JSX uses a plain string
You seeThe element carries class="title", while the rule that loaded has a longer, generated name
Check
Styles from a .module file that never reach an element with a plain string className mean the class was renamed by CSS Modules. The Next.js CSS guide says CSS Modules scope styles locally by generating unique class names, and its example reads the class from the imported object. The text title in your JSX is not the name the build produced.
grep -rn -E "className=\"[^\"]+\"" src/components/Card.jsxFix
Import the module as an object and read each class from it.
import styles from './Card.module.scss';
export function Card({ children }) {
return <div className={styles.title}>{children}</div>;
}Verify
Reload the page. The element's class is now the hashed name and the rule applies.
npm run devConfirmed by nextjs.org
Cause 2 of 4
The file name has no .module part
You seeThe component does import styles from './Card.scss' (or .css) and reads styles.title
Check
A styles object imported from a file without .module in its name holds no class map, because that file is not a CSS Module at all. Vite treats a stylesheet as a CSS Module only when its name ends in .module.css, or .module plus a pre-processor extension such as .module.scss. The same page says default imports from ordinary CSS files were removed in Vite 5, so a plain Card.scss gives you no class map.
find src -name "*.scss" -o -name "*.css" | grep -v ".module."Fix
Rename the file so it becomes a module and change the import. If you meant the file to be global instead, import it for its side effect and keep plain string classes.
git mv src/components/Card.scss src/components/Card.module.scss
// Card.jsx
import styles from './Card.module.scss';
// or, for a global stylesheet
import './Card.scss';
<div className="title" />Verify
Log the imported object. It maps each class to its generated name.
console.log(styles);Confirmed by vite.dev
Cause 3 of 4
A hyphenated class name is read with a dot
You seeThe CSS has .card-title, and the JSX says styles.card-title
Check
A CSS Modules class with a hyphen that never applies is read with dot notation. JavaScript reads styles.card-title as styles.card minus a variable called title, so the class never comes through. The CSS Modules project recommends camelCase for exactly this reason and allows bracket notation for kebab-case names.
grep -rn -E "styles\.[A-Za-z]+-[A-Za-z]" srcFix
Use bracket notation, or rename the class to camelCase. In Vite you can also turn on camelCase locals, which lets you import card-title by the name cardTitle.
<h2 className={styles['card-title']}>Title</h2>
// vite.config.js
export default {
css: { modules: { localsConvention: 'camelCaseOnly' } },
};
// Card.jsx
import { cardTitle } from './Card.module.css';
<h2 className={cardTitle}>Title</h2>Verify
Reload the page and check that the heading picks up the rule.
npm run devConfirmed by raw.githubusercontent.com
Cause 4 of 4
The rule targets a class the module did not create
You seeThe selector names a class that comes from a library or from a plain string, for example .swiper-slide inside Gallery.module.css
Check
A rule for a library class inside a .module.css file that never applies has been renamed along with your own classes. Inside a CSS Module every class selector is local, so .swiper-slide is renamed like your own classes and no longer matches the markup the library writes. The CSS Modules syntax has a :global() pseudo class to leave one selector untouched.
grep -rn -E "^\.[a-z]+-[a-z-]+" src --include='*.module.css' --include='*.module.scss'Fix
Keep your own wrapper class local and mark only the outside class as global.
/* Gallery.module.css */
.gallery :global(.swiper-slide) {
border-radius: 8px;
}Verify
Reload the page; the library's slides now take the rule, and only inside your gallery.
npm run devConfirmed by lightningcss.dev
How do I stop it coming back?
- Name every component stylesheet Name.module.css or Name.module.scss and always read classes from the imported object.
- Write class names in camelCase inside CSS Modules.
- Put styles for library markup behind one local wrapper class with :global() for the outside part.
- Keep truly global CSS in a single file imported at the root of the app.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.