Module 11 of 12

📖 HTML Validation

Validation ensures your HTML follows the official rules. Valid HTML is more predictable across browsers, more accessible, and better for SEO.

The W3C Markup Validation Service

The W3C Validator is the official tool maintained by the same organization that writes HTML standards.

Three Ways to Validate

  1. Validate by URI: Enter a live website URL
  2. Validate by File Upload: Upload your HTML file directly
  3. Validate by Direct Input: Copy and paste your HTML code

Common Validation Errors

ErrorCauseFix
Missing DOCTYPE No <!DOCTYPE html> Add it as the very first line
Unclosed tag Missing closing tag Add </tag>
Missing alt attribute Image without alt Add descriptive alt text or alt="" for decorative images
Duplicate ID Same id used twice IDs must be unique; use class for repeated styling
Invalid nesting Block element inside inline element Restructure (e.g., don't put <div> inside <span>)
✏️ Exercise 11.1: Fix Broken HTML

Download this broken.html file (or create it with intentional errors) and:

  1. Validate it at validator.w3.org
  2. Fix every error and warning
  3. Re-validate until you see: "Document checking completed. No errors or warnings to show."

📝 HTML Comments

Comments are notes in your code that browsers ignore. They help you and other developers understand your code.

Comment Syntax

<!-- This is a single-line comment --> <!-- This is a multi-line comment. Use comments to explain complex sections or mark TODO items. --> <!-- TODO: Add navigation menu here --> <nav>...</nav>

When to Use Comments

When NOT to Use Comments

⚠️ Security: Never put passwords, API keys, or private notes in HTML comments. Anyone can view them by right-clicking → "View Page Source".

📁 File and Folder Organization

A well-organized project is easier to maintain and scale.

Recommended Project Structure

my-website/ ├── index.html <!-- Homepage (always at root) --> ├── about.html <!-- About page --> ├── contact.html <!-- Contact page --> ├── css/ │ └── style.css <-- Stylesheets --> ├── js/ │ └── script.js <-- JavaScript files --> ├── images/ │ ├── logo.png │ ├── banner.jpg │ └── team/ │ ├── john.jpg │ └── jane.jpg ├── videos/ │ └── intro.mp4 └── favicon.ico <!-- Site icon -->

Naming Conventions

GoodBadWhy
about-us.htmlAbout Us.htmlNo spaces, no caps (URL-friendly)
contact.htmlpage3.htmlDescriptive names
logo.pngIMG_20230513_143022.jpgSimple, meaningful names
team/john.jpgjohnprofilepicturefinal2.jpgOrganize with folders
💡 Best Practice: Use lowercase for all filenames and folders. Separate words with hyphens (not underscores or spaces). This prevents cross-platform issues (Linux servers are case-sensitive).

🎨 Code Formatting Standards

Clean, consistent code is professional and easier to debug.

Indentation Rules

<!-- Good indentation --> <nav> <ul> <li> <a href="/">Home</a> </li> <li> <a href="/about">About</a> </li> </ul> </nav> <!-- Bad indentation (hard to read) --> <nav><ul><li><a href="/">Home</a></li><li><a href="/about">About</a></li></ul></nav>

Attribute Formatting

<!-- Good: one attribute per line for long tags --> <img src="images/photo.jpg" alt="Sunset over Lalibela churches in Ethiopia" width="800" height="600" loading="lazy">

✏️ Exercise 11.2: Audit and Fix a Page

Your Task

Take any HTML file you've created in this course and perform a complete audit:

  1. Validate it at validator.w3.org
  2. Check all images have alt attributes
  3. Ensure all id values are unique
  4. Verify every <a> has an href
  5. Check all form inputs have associated <label> elements
  6. Ensure proper heading hierarchy (no skipped levels)
  7. Fix indentation to be consistent (2 or 4 spaces)
  8. Add helpful comments for complex sections
  9. Re-validate until zero errors

📝 Module 11 Quiz

Test Your Knowledge
1. Which organization maintains the HTML validator?
2. What is the correct comment syntax?
3. Why shouldn't you use spaces in filenames?
4. What does a "duplicate ID" error mean?
5. Should you put passwords in HTML comments?

🎯 Module Summary

← Previous Module Next: Module 12 →