Knowledge Base > Development & Code > Dev Best Practices > Part 1

CSS Prefixes Explained [Part 1 of 7]

Why manual prefixing still matters (and how to do it right)


About This Guide

This guide reflects a personal methodology based on building, maintaining, and troubleshooting real-world websites. It's not theoretical or based on automated tools. These rules have been field-tested for clarity, consistency, and long-term maintainability. Your mileage may vary, but this structure has saved me countless hours.


If you've ever debugged conflicting styles across different pages, you know how fast things go sideways. This guide is for developers who work manually, not with automated CSS-in-JS tools or bundlers. It explains a real-world approach to CSS prefixing, the one used on AyotteConsulting.com.


Why Prefix CSS Per Page?

Because it prevents:

  • Class name collisions across pages
  • Accidental overwrites during layout changes
  • Headaches when debugging or scaling the site

And it ensures:

  • Visual consistency
  • Clean, readable CSS
  • Simpler maintenance

The Only Global Classes Allowed

Only these may be unprefixed:

  • Navigation-related classes (e.g. .nav-container, .nav-link)
  • Footer-related classes (e.g. .footer-block, .footer-note)

All other styles must be prefixed.

Note

The nav and footer are modular components. They're inserted into pages via <div id="navbar"></div> and <div id="footer"></div> using a small JavaScript fetch() routine.


Prefixing Rules

Every page gets its own prefix. Follow this format:

Page File Required Prefix
index.htmlindex-
about.htmlabout-
ebooks.htmlebooks-
ventures.htmlventures-
Any internal pageUse matching prefix

Correct vs Incorrect Usage

Incorrect

<div class="hero-section"></div>
.hero-section {
  padding: 2rem;
}

Correct (for index.html)

<div class="index-hero-section"></div>
.index-hero-section {
  padding: 2rem;
}

Work Process

  1. Work one page at a time.
  2. Prefix every class except nav/footer.
  3. Visually test changes.
  4. Never leave a page half-converted.
  5. Commit only when everything checks out.

What Happens If You Ignore This?

  • CSS bleed between pages
  • Broken layout and inconsistent visuals
  • Debugging hell
  • Risk of being removed from future web tasks

This isn't optional. It's the house standard.


Final Thoughts

CSS prefixing isn't glamorous, but it keeps your stylesheets sane as a project grows. If you're building multi-page sites by hand, this approach will save you real time and real headaches down the road.