0
0
NextJSframework~5 mins

CSS Modules in NextJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a CSS Module in Next.js?
A CSS Module is a CSS file where class and animation names are scoped locally by default. In Next.js, it helps avoid style conflicts by generating unique class names for each component.
Click to reveal answer
beginner
How do you import a CSS Module in a Next.js component?
You import it like a JavaScript object using: <code>import styles from './Component.module.css'</code>. Then you use the styles as <code>className={styles.className}</code> in your JSX.
Click to reveal answer
intermediate
Why use CSS Modules instead of global CSS?
CSS Modules prevent style conflicts by scoping styles locally to components. This means styles won’t accidentally affect other parts of the app, making maintenance easier and safer.
Click to reveal answer
intermediate
How does Next.js generate unique class names with CSS Modules?
Next.js automatically appends a unique hash to class names from CSS Modules. For example, <code>.button</code> might become <code>button_xyz123</code>, ensuring styles are local and don’t clash.
Click to reveal answer
intermediate
Can you use CSS Modules with global styles in Next.js?
Yes, you can use global CSS files for styles that apply everywhere, and CSS Modules for component-specific styles. Global CSS must be imported only in _app.js or _app.tsx.
Click to reveal answer
How do you apply a CSS Module class named 'header' to a div in Next.js?
A<div className={styles.header}></div>
B<div class='header'></div>
C<div className='header'></div>
D<div style={styles.header}></div>
What file extension is used for CSS Modules in Next.js?
A.module.css
B.css
C.scss
D.cssmodule
Where should you import global CSS files in a Next.js project?
AIn the page components
BOnly in _app.js or _app.tsx
CIn any component
DIn CSS Modules
What is the main benefit of using CSS Modules?
AAutomatically minifies CSS
BFaster CSS loading
CSupports inline styles
DScoped styles to avoid conflicts
If you have a class named 'button' in a CSS Module, what will Next.js do?
AUse 'button' as is globally
BIgnore the class
CGenerate a unique class name like 'button_xyz123'
DConvert it to inline styles
Explain how CSS Modules help manage styles in a Next.js project.
Think about how styles stay inside components without affecting others.
You got /4 concepts.
    Describe the difference between global CSS and CSS Modules in Next.js and when to use each.
    Consider the scope and where you import the styles.
    You got /4 concepts.