Careeroza
CSS Modules
Scoped Class Names
A file ending in .module.css is a CSS Module. Its class names are made unique at build time, so .card in one component never clashes with .card in another.
ProductCard.module.css
components/ProductCard.module.css
.card {
border: 1px solid #e5e7eb;
border-radius: 12px;
padding: 16px;
}
.price {
font-weight: 700;
color: #16a34a;
}// components/ProductCard.tsx
import styles from './ProductCard.module.css';
export default function ProductCard({ name, price }: { name: string; price: number }) {
return (
<div className={styles.card}>
<h3>{name}</h3>
<p className={styles.price}>₹{price}</p>
</div>
);
}What the Browser Gets
Example
The generated HTML uses hashed class names:
curl -s localhost:3000/products | grep ProductCardExample output
<div class="ProductCard_card__x7Qp2"><h3>Redmi Note 14</h3><p class="ProductCard_price__k1d9A">₹17999</p></div>