0
Challenge · 76Architecture & State
CSS Modules
Toolused in ~50% of apps
Two teammates both write a .button class in two different files — in plain global CSS the last one loaded silently overwrites the other. CSS Modules end that whole class of bug by scoping every class name to the file it lives in.
Core idea. A file named *.module.css gives every class a locally-scoped, build-time-hashed name, so styles can never leak between components or collide — you write readable names, the bundler guarantees uniqueness.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
Global CSSCSS Modules
Card.css
.button {
color: white;
background: blue;
}
COMPILED CLASS
.buttonDialog.css
.button {
color: white;
background: orange;
}
COMPILED CLASS
.buttonWHAT RENDERS ON THE PAGE
class="button"class="button"Collision. Both files declare .buttonin the global bucket, so the last one loaded wins — Card's blue is overwritten by Dialog's orange.
↑ play a little first, then dig in