Challenge - 5 Problems
CSS Modules Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
How does CSS Modules scope class names?
Given a Next.js component using CSS Modules, what will be the class name applied in the browser?
NextJS
/* styles.module.css */ .button { color: red; } // Component.jsx import styles from './styles.module.css'; export default function Button() { return <button className={styles.button}>Click me</button>; }
Attempts:
2 left
💡 Hint
CSS Modules automatically creates unique class names to avoid conflicts.
✗ Incorrect
CSS Modules generate unique class names by combining the original class name with a hash. This prevents styles from leaking globally.
📝 Syntax
intermediate1:30remaining
Identify the correct import statement for CSS Modules in Next.js
Which import statement correctly imports a CSS Module file in a Next.js component?
Attempts:
2 left
💡 Hint
CSS Modules require the '.module.css' extension and default import.
✗ Incorrect
Next.js requires CSS Modules to have the '.module.css' extension and be imported as a default import to get the scoped class names.
🔧 Debug
advanced2:30remaining
Why does this CSS Module class not apply styles?
Consider this Next.js component and CSS Module. Why is the button not red?
NextJS
/* styles.module.css */ .button { color: red; } // Component.jsx import styles from './styles.module.css'; export default function Button() { return <button className="button">Click me</button>; }
Attempts:
2 left
💡 Hint
Check how class names are referenced when using CSS Modules.
✗ Incorrect
Using className="button" applies a global class 'button' which does not exist. The correct way is className={styles.button} to use the scoped class.
❓ state_output
advanced2:00remaining
What is the rendered class attribute value?
Given this Next.js component using CSS Modules, what is the exact class attribute in the rendered HTML?
NextJS
/* styles.module.css */ .title { font-weight: bold; } // Title.jsx import styles from './styles.module.css'; export default function Title() { return <h1 className={styles.title}>Hello</h1>; }
Attempts:
2 left
💡 Hint
CSS Modules transform class names to unique hashes.
✗ Incorrect
CSS Modules generate a unique class name combining the original name and a hash to avoid conflicts.
🧠 Conceptual
expert3:00remaining
Why prefer CSS Modules over global CSS in Next.js?
Which is the main advantage of using CSS Modules instead of global CSS files in Next.js projects?
Attempts:
2 left
💡 Hint
Think about how styles affect other parts of the app.
✗ Incorrect
CSS Modules scope styles locally, so styles do not leak or override each other globally, making maintenance easier.