Performance: CSS Modules support
This affects page load speed by controlling CSS scope and bundle size, impacting render blocking and style recalculation.
import styles from './Button.module.css'; <div className={styles.primary}>Click me</div>
/* global.css loaded everywhere */ import './global.css'; <div class="button primary">Click me</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global CSS | N/A | Multiple reflows on style changes | High paint cost due to large CSS | [X] Bad |
| CSS Modules | Scoped to component nodes | Single reflow limited to component | Lower paint cost with smaller CSS | [OK] Good |
CSS Modules in Astro components?styles.module.css in an Astro component?import styles from './filename.module.css';.import styles from './button.module.css'; and the CSS file containing .primary { color: blue; }, what will be the rendered class attribute for <button class={styles.primary}>Click</button>?button_primary__abc123 to avoid conflicts.styles.primary applies the transformed unique class name, not the original 'primary'. So the class attribute will be a unique hashed string.import styles from './card.module.css';
export default function Card() {
return <div class="styles.card">Content</div>;
}class={styles.card}."styles.card", which treats it as a string literal, not the variable. This causes the class to be literally 'styles.card' instead of the hashed class.styles.primary and styles.rounded to a single element in an Astro component?<div class={`${styles.primary} ${styles.rounded}`}>Content</div> correctly uses template literals to combine classes with a space. <div class="styles.primary styles.rounded">Content</div> treats class names as literal strings, not variables. <div class={styles.primary + styles.rounded}>Content</div> concatenates without space, merging class names incorrectly. <div class={styles.primary, styles.rounded}>Content</div> uses comma which is invalid syntax.Pass the test and this pattern moves unknown