Consider an Astro component using CSS Modules. What happens to the CSS class names when the component is rendered in the browser?
<style module>
.button {
color: red;
}
</style>
<button class={styles.button}>Click me</button>Think about how CSS Modules prevent style conflicts by changing class names.
CSS Modules automatically generate unique class names by hashing the original class name and file path. This ensures styles are scoped locally to the component and do not clash with other styles.
Which of the following is the correct way to import and use a CSS Module file named Button.module.css in an Astro component?
Astro supports ES module imports for CSS Modules.
In Astro, CSS Modules are imported as ES modules using import styles from './filename.module.css'. This allows you to access scoped class names via the styles object.
Given this Astro component code, the styles from the CSS Module are not applied. What is the most likely cause?
---
import styles from './Card.module.css';
---
Card content
Check how dynamic class names are passed in JSX-like syntax.
In Astro, to use a class from a CSS Module, you must use curly braces to evaluate the JavaScript expression. Using quotes treats it as a literal string, so the styles won't apply.
Given this Astro component using CSS Modules, what will be the exact value of the class attribute in the rendered HTML?
---
import styles from './Alert.module.css';
---
Warning!
Assume the original CSS class is alert and Astro generates a hash _Alert_alert_1a2b3.
CSS Modules replace class names with unique hashed names.
The class name is replaced by a unique hashed string combining the component name, original class, and a hash to ensure uniqueness and avoid conflicts.
Which of the following is the best explanation for why CSS Modules are preferred over global CSS in Astro projects?
Think about how styles can accidentally affect other parts of a website.
CSS Modules scope styles to the component, so styles do not leak or override other components' styles. This avoids bugs and makes maintenance easier.