Skip to main content

What is CSS?

CSS (Cascading Style Sheets) is the standard language for controlling the visual presentation of web pages — the colors, layout, spacing, typography, animations, and responsive behavior that make the difference between a raw HTML document and a polished website.


1. The Role of CSS in the Web Stack

The web is built on three foundational technologies that each have a distinct, non-overlapping purpose:

┌─────────────────────────────────────────────────────────────┐
│ THE WEB STACK │
│ │
│ HTML ──► STRUCTURE (what the content IS) │
│ CSS ──► PRESENTATION (how the content LOOKS) │
│ JS ──► BEHAVIOR (how the content ACTS) │
└─────────────────────────────────────────────────────────────┘

Think of it like a building:

  • HTML is the architectural blueprint — the walls, floors, and rooms.
  • CSS is the paint, flooring, lighting, furniture, and interior design.
  • JavaScript is the electrical wiring, smart locks, and elevator systems.

A common mistake is mixing these responsibilities — using JavaScript to change colors when CSS can do it, or using HTML style="" attributes when a CSS class is better. Keeping these three concerns separated makes your code maintainable, readable, and easier to hand off to AI tools.


2. What CSS Actually Controls

Typography: font-family, font-size, font-weight, line-height, letter-spacing
Color: color, background-color, gradient, opacity
Spacing: margin, padding, gap
Layout: Flexbox, Grid, position (sticky, fixed, absolute)
Size: width, height, max-width, aspect-ratio, clamp()
Borders + Shapes: border, border-radius, outline
Visual Effects: box-shadow, filter, backdrop-filter, mix-blend-mode
Animation: transition, animation, @keyframes, scroll-driven
Responsive: media queries, container queries, fluid sizing
State styles: :hover, :focus, :checked, :is(), :has()
Generated content: ::before, ::after
Screen adaptation: dark mode, print styles, prefers-reduced-motion

3. Why "Cascading"?

The word Cascading describes the algorithm CSS uses to resolve conflicts — when multiple rules target the same element, how does the browser decide which one wins?

The Cascade Priority Order

Highest Priority

│ 1. !important declarations (author)
│ 2. Inline styles (style="...")
│ 3. @layer order (later layers win)
│ 4. Specificity (how targeted the selector is)
│ 5. Source order (last rule wins when equal)
│ 6. Browser default stylesheet (user-agent)

Lowest Priority

Specificity at a Glance

Selector Type Specificity Weight Example
────────────────────────────────────────────────────────
Inline style 1,0,0,0 style="color:red"
ID selector 0,1,0,0 #header
Class / attribute 0,0,1,0 .btn [type="text"]
Element / pseudo-el 0,0,0,1 h1 ::before
Universal 0,0,0,0 *
────────────────────────────────────────────────────────
Higher number = higher priority. Compare left-to-right.
/* Example specificity conflict */
p { color: blue; } /* 0,0,0,1 — element selector */
.text { color: red; } /* 0,0,1,0 — class selector — WINS over p */
#main p { color: green; } /* 0,1,0,1 — ID + element — WINS over .text */

[!TIP] The cascade is not a bug — it's a feature. Mastering it means you can control exactly which rules apply without reaching for !important.


4. A Brief History of CSS

VersionYearKey Additions
CSS 11996Fonts, colors, margins, basic text styles
CSS 21998Positioning, z-index, media types, @import
CSS 2.12004–2011Bug fixes, clarifications — most widely implemented
CSS 32011+Split into modules — each evolves independently
Grid + Flexbox2017The modern layout revolution
Custom Properties2017CSS variables (:root { --color: red; })
Container Queries2022Component-level responsive design
@layer2022Cascade layer control — native ITCSS
:has()2023Parent selector — game-changing
OKLCH colors2023Perceptually uniform color space
CSS Nesting2024Sass-like nesting in native CSS

[!NOTE] There is no "CSS 4" as a single release. CSS now uses a modular specification — Grid, Flexbox, Animations, Custom Properties, and Color each have their own spec with independent timelines. When you hear "CSS 4 selectors," it means the Selectors Level 4 spec, not a CSS version.


5. How the Browser Processes CSS

1. Request HTML from server

2. Parse HTML → Build the DOM (Document Object Model)
(encounters <link rel="stylesheet"> → pauses to fetch CSS)

3. Download and Parse CSS → Build the CSSOM (CSS Object Model)

4. Combine DOM + CSSOM → Render Tree
(elements with display:none are excluded at this stage)

5. Layout (Reflow): Calculate exact position and size of every element

6. Paint: Fill pixels — text, colors, images, shadows, borders

7. Composite: Assemble layers on the GPU and display

Why This Matters for Performance

/* ✅ These properties skip Layout and Paint — only Composite step */
/* Cheap to animate — GPU-accelerated */
transform: translateY(-4px);
opacity: 0.8;

/* ❌ These trigger Layout (Reflow) — most expensive */
width: 200px → 300px; /* Triggers full layout recalculation */
height: auto → 200px; /* Same */
top: 0 → 50px; /* Same (with position:relative) */

/* ⚠ These trigger Paint — medium cost */
background-color: change; /* Repaints the element */
color: change; /* Repaints */
box-shadow: change; /* Repaints */

6. CSS in the AI + WordPress Workflow

In this curriculum, CSS knowledge serves a specific professional purpose — giving you the technical authority to direct AI tools and build production-quality WordPress sites:

What You Can Do With CSS Mastery

AI Direction:
→ Write precise prompts that get BEM-compliant, token-using CSS first time
→ Audit AI output — spot specificity bugs, invalid syntax, outdated patterns
→ Correct AI mistakes (unnecessary vendor prefixes, !important abuse, etc.)

WordPress Development:
→ Build child themes that don't break when the parent theme updates
→ Override plugin CSS (WooCommerce, CF7) with correct specificity
→ Use CSS custom properties for a consistent design system
→ Style Gutenberg blocks, GeneratePress, GenerateBlocks, Bricks Builder

Design System:
→ Create reusable components with BEM naming
→ Manage the cascade with @layer
→ Build responsive layouts with Grid and Container Queries
→ Implement dark mode, animations, and accessibility

7. Core CSS Philosophies

PrincipleMeaningIn Practice
Separation of ConcernsHTML = structure, CSS = styleNever use style="" for permanent styles; keep CSS in stylesheets
DRY (Don't Repeat Yourself)Define once, reuse everywhereCSS custom properties (--color-primary), shared component classes
Progressive EnhancementBuild for all, enhance for modernAlways have fallbacks before using new CSS features
Mobile FirstStyle small screens first, enhance upBase styles → min-width media queries to expand
Cascade AwarenessKnow which rule wins and whyUse specificity and @layer intentionally, avoid !important
Component ThinkingCSS reflects the UI component modelBEM naming, one class = one visual responsibility

8. CSS vs Inline Styles vs CSS-in-JS

Method When to Use Avoid When
──────────────────────────────────────────────────────────────────
External CSS file Always — the default Never avoid this
Internal <style> Single-page special cases Production, multi-page
Inline style="" Dynamic JS-set values only Permanent styles
CSS-in-JS React/Vue component libs WordPress, no build step
CSS Modules React apps with Vite/Next WordPress
Tailwind utilities Prototyping, React apps WordPress without build

9. The Mental Model: CSS Rules

Every CSS rule has the same structure — memorise this once and it never changes:

/* ┌────────── SELECTOR ──────────┐ */
.c-btn--primary:hover {
/* └──────────────────────────────┘ */

/* ┌────── DECLARATION BLOCK ─────────────────────────────────┐ */
background-color: var(--color-primary-dark); /* property: value */
transform: translateY(-2px);
box-shadow: var(--shadow-primary);
/* └──────────────────────────────────────────────────────────┘ */
}

/* Components:
Selector = targets the HTML element
Property = the CSS attribute to change
Value = what to change it to
Declaration = property + value (one line)
Rule = selector + declaration block
*/