CSS
Cascading Style Sheets — the language for styling web pages. CSS controls colors, fonts, layout, spacing, and responsive design. Without it, HTML is unstyled text. Modern CSS (Flexbox, Grid, custom properties) handles most layout needs without preprocessors.
Håkon Wium Lie · Proposed CSS in 1994, co-created with Bert Bos
- Every web page for styling.
- Responsive layouts with media queries and Grid/Flexbox.
- Styling native apps (use platform styling).
- Complex animations (use JS/Canvas for control).
Definition
CSS selects HTML elements via selectors and applies style rules (properties). The cascade resolves conflicts by specificity and source order. Modern CSS includes Flexbox (1D layout), Grid (2D layout), custom properties (variables), and container queries. Responsive design uses media queries and relative units.
Why it exists
To separate presentation from structure so the same HTML can be styled differently for different devices, themes, and contexts.
How it works
Write CSS rules (selector { property: value }). The browser matches selectors to DOM elements, resolves the cascade, computes styles, and lays out/paints the page. Styles can be external files, inline, or in <style> tags.
Scaling limits
Global scope and specificity wars in large codebases (mitigated by CSS Modules, Tailwind, or scoped styles). Performance: large CSS files block rendering. Complex selectors can be slow to match.
Cost shape
Free. The cost is developer tooling (preprocessors, frameworks) and CSS payload size affecting load.
Alternatives
- Tailwind CSS — Utility-first, no custom class names, but HTML gets verbose.
- CSS-in-JS — Scoped styles in JS, but runtime overhead and larger bundles.
Failure modes
- Specificity wars making overrides hard.
- !important abuse.
- Global styles leaking across components.
Related terms
HTML, DOM, Tailwind CSS, Flexbox, CSS Grid, Responsive design