🎨 CSS — Code-First Engineering Reference

A 22-chapter deep-dive reference for mid-to-senior engineers. Each chapter is structured around annotated production code: complex implementations, anti-pattern→correct pairs, performance tips, and edge cases. Minimal prose, maximum code. DevTools is the REPL.

How to Use This Reference

  1. Read sequentially (01 → 22) for a structured engine-deep path.
  2. Jump to a chapter when you hit a concept in production — every chapter is self-contained.
  3. Skim the anti-pattern → correct pairs — they're the highest-signal sections.
  4. Read the 🧠 Spot the Bug at the end of each chapter before checking the answer.

Prerequisites

  • A modern browser (Chrome, Firefox, Safari, Edge). DevTools (Cmd+Opt+I).
  • A code editor (VS Code recommended).
  • Working HTML knowledge.
  • Comfort reading CSS — this is a reference, not a beginner tutorial.

Curriculum

Part I — Engine Foundations

#TopicWhy It Matters
01CSS Engine Internals & Production SetupParse → box tree → cascade → layout → paint → composite. @layer architecture from line one.
02Selectors, Specificity & the Cascade AlgorithmRight-to-left matching, the 4-tuple specificity, cascade layers as the precedence primitive.
03The Box Model: Formatting Contexts & Margin Collapsebox-sizing, BFC, margin-collapse rules, the min-width: auto flex/grid killer.
04Color Spaces, Units & the Fluid Math of CSSOKLCH perceptual uniformity, em/rem compounding, calc/min/max/clamp, color-mix.
05Typography Engine: Font Loading & Text Overflowfont-display strategies, variable font axes, unitless line-height, single/multi-line truncation.

Part II — Layout Algorithms

#TopicWhy It Matters
06Display, Position & the Containing BlockFormatting contexts, the five position schemes, the transform-ancestor trap that breaks fixed.
07Flexbox: One-Dimensional Layout & the flex Algorithmgrow/shrink/basis resolution, min-width: auto, gap, the app-layout pattern.
08CSS Grid: Two-Dimensional Layout & Track Resolutionfr distribution, minmax(0, 1fr) overflow fix, auto-fit vs auto-fill, grid-template-areas, subgrid.
09Responsive Design: Media Queries, Container Queries & Fluid CSSMobile-first, fluid clamp/auto-fit, container queries, prefers-* media features.
10Floats, z-index & the Stacking Context ModelStacking-context creation rules, the ancestor-z-index trap, isolation: isolate, clip-path.

Part III — Visual Compositing

#TopicWhy It Matters
11Backgrounds & Gradients: Layering & the Shorthand Reset TrapMultiple layers, background-size / syntax, background-clip: text, conic-gradient pie charts.
12Borders, Shadows, Outlines & Focus StatesLayered elevation, outline vs border (layout shift), :focus-visible, the overflow-clips-shadow trap.
13Animations & Transitions: The Compositor PipelineGPU vs layout-triggering properties, cubic-bezier overshoot, the height: auto trap, grid-template-rows.
14Filters, Blend Modes & Masking: Compositing Pipelinedrop-shadow vs box-shadow, backdrop-filter translucency, mix-blend-mode contexts, mask soft fades.

Part IV — Modern CSS Primitives

#TopicWhy It Matters
15CSS Variables: Custom Properties as the Theming EngineCascade/inheritance, invalid-value semantics, runtime theming, JS setProperty bridge.
16Logical Properties & Writing Modes: i18n-Ready CSSinline/block axes, logical equivalents, vertical-rl, the logical/physical mixing trap.
17Modern CSS (2023+): Nesting, (), Layers & color-mixNative nesting, :has(), @layer, container style queries, color-mix, scroll-driven animations.
18Architecture: BEM, OOCSS, ITCSS, Atomic & Cascade LayersFlat-specificity naming, structure/skin separation, @layer as the native architecture primitive.

Part V — Production Engineering

#TopicWhy It Matters
19CSS Performance: Render Path, Containment & GPU LayersCritical CSS, layout thrashing, content-visibility: auto, contain, will-change memory cost.
20Browser Compatibility: Prefixes, @supports & Progressive EnhancementAutoprefixer/browserslist, @supports feature detection, the Safari -webkit- laggard trap.
21Preprocessors & Build Tools: Sass, PostCSS, Vite & CSS Modules@use vs deprecated @import, compile-time vs runtime variables, PostCSS chains, CSS Modules.
22Exercises & Projects: Production CSS Systems7 projects: layered reset, navbar, grid dashboard, glassmorphism, tooltips, loaders, capstone.

Learning Path Suggestions

Mid-level developer moving to senior

Read 01 (engine + @layer), 02 (cascade algorithm), 07–08 (flex/grid algorithms — the min-width and minmax(0,1fr) traps), 13 (compositor pipeline — what animates at 60fps), 17 (:has(), @layer, container queries), 19 (render path + content-visibility), 18 (architecture).

Coming from a framework (React/Vue/Tailwind)

Read 02 (specificity — you've been insulated), 06 (containing block — the fixed + transform trap), 08 (grid track resolution), 13 (which properties animate on GPU), 15 (CSS variables as the JS↔CSS bridge), 18 (BEM + @layer vs utility-first).

Senior frontend engineer

Skim 01–05. Read closely: 10 (stacking contexts — the cage model), 13 (compositor pipeline), 14 (compositing gotchas), 16 (logical properties for i18n), 17 (2023+ features), 19 (content-visibility, contain, GPU layers), 21 (Sass vs CSS variables, build pipeline).

Performance-focused

Read 13 (compositor-only properties), 19 (render path, content-visibility: auto, contain, will-change), 11 (shorthand reset trap), 05 (font loading, font-display), 09 (fluid CSS vs media queries).

Companion Resources

Tooling

bash
# VS Code extensions: Live Server (hot reload), CSS Peek (jump to definition), Tailwind IntelliSense (if Tailwind)
# Browser DevTools: Cmd+Opt+I → Elements/Inspector. Coverage tab (unused CSS), Rendering tab (paint flashing, CLS), Layers panel (GPU layers).

License

These notes are yours to use, share, and modify.