CSS as the presentation layer of the web
Cascading Style Sheets attach presentation to document structure: selectors match elements in the DOM tree, declarations set properties, and the cascade resolves conflicts by origin, specificity, and order. Authors work with the box model, positioning, flex and grid, typography, and responsive @media rules—often copied from DevTools or build output as compact text.
Pretty-printing reveals rule boundaries and nesting for review; minification removes comments and insignificant whitespace for transfer size. Neither rewrites selectors for specificity wars, adds vendor prefixes, or purges unused rules—that belongs to PostCSS, bundlers, and design systems.
CSS syntax — background
Rules, selectors, and declarations
- A rule pairs a selector list with a declaration block in braces.
- Selectors target elements, classes, IDs, attributes, pseudo-classes, and pseudo-elements; combinators (>, +, ~, space) express structure.
- Each declaration is property: value with an optional !important flag; semicolons separate declarations.
- Shorthand properties (margin, font, background) expand to longhands in the computed style.
Cascade, inheritance, and specificity
- Inherited properties (color, font-family) flow from parent to child unless overridden.
- Specificity compares ID, class/attribute/pseudo-class, and type/pseudo-element counts; !important and inline styles outrank author rules in defined orders.
- Later rules in the same origin and layer win when specificity ties.
- @layer and @import order (in supporting engines) group author intent before specificity alone decides.
At-rules and responsive layout
- @media wraps rules that apply only when viewport or feature queries match.
- @keyframes name animation phases with percentage or from/to keyframes.
- @font-face registers webfont files; @supports gates rules on parser/feature tests.
- Custom properties (--token) store values inherited through the subtree like variables.
From declared rules to used values on screen
- Specified values cascade through inheritance and initial defaults before computation.
- Used values resolve percentages and em/rem against containing blocks and root font size.
- Stacking contexts order painted layers; z-index only compares within the same context.
- Custom properties inherit through the subtree and participate in var() substitution at computed-value time.
Where readable CSS helps
DevTools and bundle review
One-line production CSS hides @media nesting—indentation exposes breakpoint groupings during incident or perf reviews without running a full build.
Design handoffs and email inline styles
Pasted declaration blocks from style attributes or partial sheets become diff-friendly before merge into components or templates.