0
0
NextJSframework~20 mins

CSS Modules in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Modules Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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>;
}
AA unique hashed class name like 'button_xyz123' scoped to this component
BThe literal class name 'button' applied globally
CNo class name applied because CSS Modules disables styling
DA random string unrelated to 'button' or the file name
Attempts:
2 left
💡 Hint
CSS Modules automatically creates unique class names to avoid conflicts.
📝 Syntax
intermediate
1: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?
Aimport styles from './styles.module.css';
Bimport './styles.module.css';
Cimport styles from './styles.css';
Dimport styles from './styles.module.scss';
Attempts:
2 left
💡 Hint
CSS Modules require the '.module.css' extension and default import.
🔧 Debug
advanced
2: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>;
}
AThe CSS file is missing an import statement in the component.
BThe className should use styles.button, not the string 'button', to apply scoped styles.
CCSS Modules do not support the 'color' property.
DThe button element must be wrapped in a div for styles to apply.
Attempts:
2 left
💡 Hint
Check how class names are referenced when using CSS Modules.
state_output
advanced
2: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>;
}
Aclass="styles_title" (the variable name as string)
Bclass="title" (the plain class name)
Cclass="title_abc123" (a unique hashed class name)
DNo class attribute is rendered
Attempts:
2 left
💡 Hint
CSS Modules transform class names to unique hashes.
🧠 Conceptual
expert
3: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?
ACSS Modules load styles faster than global CSS files.
BCSS Modules automatically convert CSS to inline styles.
CCSS Modules allow writing CSS inside JavaScript files without separate CSS files.
DCSS Modules scope styles locally to components, preventing style conflicts across the app.
Attempts:
2 left
💡 Hint
Think about how styles affect other parts of the app.