$html-docs
InstallDevelopersPricingSign inOpen drive
All HTML guides
Foundations7 min read·July 29, 2026

How to Organize CSS Around Your HTML

Keep selectors shallow, components readable, and design tokens explicit so a page remains easy to revise after launch.

The short version

CSS stays maintainable when the markup exposes stable component boundaries.

01

Start with tokens and a small base

Define recurring colors, spacing, radii, and type choices once. Keep the base layer focused on document defaults. A token should represent a real design decision, not merely rename a single value.

css
:root {
  --paper: #fafaf7;
  --ink: #151513;
  --mark: #f0dc55;
  --space-3: 0.75rem;
  --radius: 0.5rem;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}
02

Prefer component classes to clever selectors

A class such as .article-card describes a durable boundary. A selector that depends on the fifth div inside a particular section breaks as soon as the HTML changes. Keep specificity low and states explicit.

  • Use classes for components and variants.
  • Avoid ids for styling.
  • Keep nesting shallow.
  • Co-locate responsive rules with the component when practical.
  • Delete selectors when their markup disappears.
03

Make editing safe

Imported or collaborative HTML changes over time. Styles that target semantic elements and stable classes survive region edits better than styles tied to exact child positions. Test the page with longer headings, empty states, and unexpected lists before calling the stylesheet finished.

Official references

  • web.dev: Learn CSS
  • W3C: CSS specifications

In this guide

  1. 01Start with tokens and a small base
  2. 02Prefer component classes to clever selectors
  3. 03Make editing safe
Publish a page

Keep going

Related HTML guides

Browse all 24 guides
Foundations7 min read

How to Write Semantic HTML That Stays Useful

Choose elements for their meaning, build a clear document outline, and make your page easier to navigate, edit, and reuse.

Read guide
Foundations6 min read

A Reusable HTML Page Structure for New Projects

Begin with a small, valid document shell that supports accessibility, responsive design, metadata, and progressive enhancement.

Read guide
Foundations6 min read

How to Add Dark Mode Without Breaking Your HTML

Respect system preferences, preserve contrast, and keep native controls and embedded content legible in both themes.

Read guide
© 2026 HTML DocsInstallSupportPrivacyTermsAPI