Lesson 39 of 50
cssCSS Architecture – BEM, OOCSS, SMACSS, ITCSS
12 mins
Course progress78%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 39 of 50
css12 mins
Keep these ideas in mind as you work through the lesson.
A solid CSS architecture keeps styles predictable, reusable, and scalable.
| Method | Core Idea | When to Use |
|---|---|---|
| BEM | Block __ Element -- Modifier (e.g., .card__title--large). | Component‑heavy UI libraries, large teams. |
| OOCSS | Separate structure (layout) from skin (visuals). | When you notice many elements sharing the same box model. |
| SMACSS | Categorises rules: Base, Layout, Module, State, Theme. | Projects that need a clear layer distinction. |
| ITCSS | Inverted Triangle – from generic to explicit (variables → utilities → components → trumps). | Large, complex code‑bases where cascade order matters a lot. |
<button class="btn btn--primary">Click me</button>
/* Block */
.btn { padding:0.6rem 1.2rem; border:none; cursor:pointer; }
/* Modifier */
.btn--primary { background:#0066cc; color:#fff; }
/* Element (if needed) */
.btn__icon { margin-right:0.5rem; }
/* Object – reusable layout */
.media { display:flex; align-items:center; }
/* Skin – colour, typographic tweaks */
.media--highlight { background:#fffae6; }
/* Layout */
.l-header { grid-area:header; }
.l-main { grid-area:main; }
.l-footer { grid-area:footer; }
/* Module */
.card { border:1px solid #e0e0e0; }
/* State */
.is-active { opacity:1; }
/* Theme */
.theme-dark .card { background:#111; color:#eee; }
.u-hidden).!important).Never use a trump class to hide content (.is-hidden { display:none; }) without also handling focus management; otherwise keyboard users may get trapped.