HTML Style Guide

🧾 Why Follow an HTML Style Guide?

A consistent HTML Style Guide ensures your code is readable, maintainable, and scalable. Whether you're working solo or in a team, clean code helps avoid confusion and improves collaboration. πŸ’ΌπŸ› οΈ

>>β€œAny fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler πŸ‘¨β€πŸ’»

πŸ”  Naming Conventions

  • βœ… Use lowercase for all HTML element names: <div>, <section>
  • πŸ’‘ Use hyphens (not underscores or camelCase) for class names: menu-item
  • πŸ“› IDs should also be lowercase and descriptive: main-header

🧹 Code Formatting

  • βœ… Use proper indentation (usually 2 or 4 spaces)
  • 🧱 Nest elements properly for clarity
  • βœ… Always close tags (even optional ones like <li>)

Well-Formatted HTML

<ul>
  <li>Home</li>
  <li>About</li>
  <li>Contact</li>
</ul>

Note

⚠️ Avoid using tab and space interchangeably. Stick to one indentation style consistently.

πŸ—‚οΈ File Organization

  • 🧾 Keep HTML files organized in a logical folder structure
  • πŸ“‚ Separate CSS and JavaScript into their own folders (e.g., css/, js/)
  • πŸ–ΌοΈ Store images in a dedicated images/ folder

πŸ§ͺ Use Semantic HTML

Always prefer semantic tags like <header>, <main>, <article>, and <footer> over generic <div> when possible.

Note

πŸ’‘ Semantic elements help improve accessibility, SEO, and clarity.

πŸ”€ Quotes and Attributes

  • βœ… Always use double quotes for attribute values: <img src="logo.png" alt="Logo" />
  • βœ… Always include the alt attribute for images

🧼 Commenting

  • πŸ’¬ Use comments to describe sections: <!-- Main Navigation -->
  • βœ… Keep comments brief and meaningful

HTML Comments

<!-- Start of Header -->
<header>
  <h1>My Site</h1>
</header>

πŸ“˜ Best Practices Summary

RuleDoDon't
Element Names<section><SECTION>
Class Namingcard-titleCardTitle or card_title
Indentation2 or 4 spacesNo indentation or tabs + spaces mixed
Imagesalt="..." providedNo alt attribute

πŸ”— Additional Resources

>>β€œCode is like humor. When you have to explain it, it’s bad.” – Cory House πŸ˜‚