I'm working on a Next.js project and using CSS Modules for styling individual components (e.g., Login.module.css
for a Login
component). My current workflow looks like this:
className="..."
with
className={styles.className}
.This process is a bit tedious, especially compared to just writing for example className="titleLogin"
directly.
Example:
// What I’d prefer to do at first
<div className="loginTitle">Login title</div>
// What I end up needing for CSS Modules
<div className={styles.titleLogin}>Login title</div>
Typing styles.
every time slows me down during layout and prototyping. When I have multiple class names inside a div
, really annoys me.
My Question:
Is there a better or more efficient way to work with CSS Modules in Next.js to avoid having to manually rewrite every class name with styles.
after creating the markup?
I’m open to best practices, tooling suggestions, or workflow tips that can make working with CSS Modules less repetitive during development.
I suggest you to use vscode extension if you are using visual studio code for development.
VSCode Extension – IntelliSense for CSS Modules
It gives autocompletion and type-checking for styles.
If you want to become a nextjs developer, you must be familiar with TailwindCSS
.
It's utility-first, avoids className mapping entirely, and is popular in the Next.js community.