HTML
I. HTML Fundamentals
1. Introduction to HTML
2. How the Web Works
3. HTML Document Structure
4. HTML Elements and Tags
5. HTML Attributes
6. Text Formatting Tags
7. Headings and Paragraphs
8. Comments and Whitespace
II. Core HTML Elements
9. Links and Navigation
10. Images and Media
11. Lists in HTML
12. Tables in HTML
13. Forms Overview
14. Input Types
15. Form Validation Basics
16. Buttons and Actions
III. Advanced HTML & Semantics
17. Semantic HTML
18. Layout Elements
19. Audio and Video
20. Iframes and Embeds
21. Meta Tags and SEO
22. Accessibility Basics
23. ARIA Attributes
24. Responsive HTML
IV. Best Practices & Projects
25. HTML Best Practices
26. Clean and Readable HTML
27. HTML Performance Tips
28. HTML Security Basics
29. Browser Compatibility
30. Debugging HTML
31. Mini Project – Portfolio Page
32. Mini Project – Landing Page
33. Mini Project – Form Page
34. Mini Project – Blog Layout
35. HTML Interview Questions
36. HTML Real-World Use Cases
37. HTML Case Study
38. HTML Project Planning
39. HTML Final Project
40. HTML Course Wrap-Up
LESSON 8
Comments and Whitespace
Master hidden notes in your HTML and control spacing for cleaner, more readable code.
Comments are like sticky notes for your HTML. They're completely invisible to visitors but help you remember why you wrote something. Think of them as secret messages that only you and other developers can see when looking at the code. Whitespace means all the empty space in your code — the spaces between words, blank lines, and tabs. HTML treats whitespace in a special way that might surprise you.HTML Comments
Comments start with ``. Everything between these markers becomes invisible to the browser. You can write anything inside a comment — notes about what the code does, reminders for later, or temporarily hide code without deleting it.<!--
Your comment text here
-->
Opening tag (orange) + content (gray) + closing tag (orange)
<!-- Navigation section for Alex's portfolio -->
<nav>
<a href="index.html">Home</a>
<a href="projects.html">Projects</a>
<a href="contact.html">Contact</a>
</nav>
<!-- Main content area -->
<main>
<h1>Welcome to My Portfolio</h1>
<p>I'm a web developer passionate about creating amazing websites.</p>
<!-- TODO: Add more about me content later -->
</main>localhost/index.html
What just happened?
All the comments disappeared completely. The navigation and heading rendered normally, but visitors never see the notes about "Navigation section" or "TODO" reminders. Comments are your invisible helpers.
Common Comment Uses
Professional developers use comments for several important reasons. They mark different sections of a page, explain complex code, leave reminders for future updates, and temporarily disable code without deleting it.Section Markers
Mark the start and end of major page sections like header, main content, and footer.
Code Explanations
Explain why you chose certain HTML structures or what they accomplish.
TODO Reminders
Note features to add later, content to update, or improvements to make.
Temporary Hiding
Hide code temporarily while testing instead of deleting it completely.
<!-- ========== HEADER SECTION ========== -->
<header>
<h1>Alex Thompson</h1>
<p>Web Developer & Designer</p>
</header>
<!-- ========== MAIN CONTENT ========== -->
<main>
<!-- About me section -->
<section>
<h2>About Me</h2>
<p>I love creating websites that make people smile.</p>
<!-- TODO: Add photo of me here -->
</section>
<!-- Temporarily hiding skills section until content is ready
<section>
<h2>My Skills</h2>
<p>HTML, CSS, JavaScript</p>
</section>
-->
</main>localhost/index.html
What just happened?
Only the header and "About Me" section appeared. The skills section got completely hidden because it was wrapped in comment tags. Notice how the `` reminder also disappeared.
Understanding Whitespace
Whitespace includes spaces, tabs, and line breaks in your HTML code. Browsers handle whitespace in a way that often surprises beginners — they collapse multiple spaces into just one space, and they ignore most line breaks completely. This means you can format your code however makes it easiest to read. The browser will display the content the same way regardless of your spacing choices.<!-- All of these create the EXACT same result -->
<!-- Version 1: Everything on one line -->
<p>Hello world this has lots of spaces</p>
<!-- Version 2: Split across multiple lines -->
<p>Hello world
this has
lots of spaces</p>
<!-- Version 3: Nicely formatted -->
<p>
Hello world
this has
lots of spaces
</p>localhost/index.html
What just happened?
All three paragraphs look identical! The browser collapsed all those extra spaces into single spaces and ignored the line breaks. Each paragraph shows "Hello world this has lots of spaces" with normal spacing.
Whitespace Collapse Rules
The browser follows specific rules when handling whitespace. Multiple consecutive spaces become one space. Line breaks become spaces (or disappear entirely). Leading and trailing spaces get removed. Tabs get treated like regular spaces. Here's exactly how Alex's portfolio content would render with different whitespace:<!-- Testing whitespace in Alex's portfolio -->
<h1>Alex Thompson</h1>
<p>I'm a web developer who loves
creating beautiful websites that
make people happy.</p>
<p>My favorite technologies:
HTML
CSS
JavaScript</p>localhost/index.html
What just happened?
The heading shows "Alex Thompson" with normal spacing. The paragraph text flowed together into regular sentences. The technology list became one line: "My favorite technologies: HTML CSS JavaScript" because line breaks turned into spaces.
Clean Code Formatting
Good formatting makes your HTML easier to read and maintain. You should use consistent indentation (usually 2 spaces per level), add blank lines between major sections, align related elements, and keep lines reasonably short. Professional developers format their code like this because it makes mistakes easier to spot and helps team members understand the structure quickly.Messy Formatting
<header><h1>Alex</h1><p>Developer</p></header><main><section><h2>About</h2><p>I make websites</p></section></main>
Clean Formatting
<header>
<h1>Alex</h1>
<p>Developer</p>
</header>
<main>
<section>
<h2>About</h2>
<p>I make websites</p>
</section>
</main>
<h1>Alex</h1>
<p>Developer</p>
</header>
<main>
<section>
<h2>About</h2>
<p>I make websites</p>
</section>
</main>
<!-- Alex's Portfolio - Clean Formatting Example -->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Page information -->
<meta charset="UTF-8">
<title>Alex Thompson - Web Developer</title>
</head>
<body>
<!-- ========== HEADER SECTION ========== -->
<header>
<h1>Alex Thompson</h1>
<p>Creative Web Developer</p>
</header>
<!-- ========== MAIN CONTENT ========== -->
<main>
<section>
<h2>Welcome</h2>
<p>Thanks for visiting my portfolio. I create websites that users love.</p>
</section>
</main>
<!-- ========== FOOTER SECTION ========== -->
<footer>
<p>© 2024 Alex Thompson</p>
</footer>
</body>
</html>localhost/index.html
What just happened?
The page rendered perfectly with clear header, main content, and footer sections. All the clean formatting and helpful comments disappeared in the browser but made the code much easier to understand for developers.
Common Mistakes
New developers often make specific mistakes with comments and whitespace. Here are the most common ones and how to fix them.Forgetting Comment Closing
Writing `` breaks your entire page. Always close comments properly.
<!-- BROKEN: Missing closing -->
<!-- This comment never ends
<h1>This heading won't appear</h1>
<p>Neither will this paragraph</p>
<!-- FIXED: Properly closed -->
<!-- This comment ends correctly -->
<h1>This heading appears perfectly</h1>
<p>And so does this paragraph</p>localhost/index.html
Most code editors highlight unclosed comments in different colors, making this mistake easy to spot. VS Code shows unclosed comments in gray that extends beyond where it should end.
Pro Developer Tips
Professional developers follow specific patterns that make their HTML bulletproof. Always use consistent indentation (2 spaces is standard). Add comments before major sections, not after. Write TODO comments in ALL CAPS so they're easy to find. Remove commented-out code before going live. Most importantly, format your code like someone else will need to read it — because they will! Future you will thank present you for clear, well-commented HTML. Companies like Apple and GitHub have strict formatting standards that all their developers follow. Clean, consistent code prevents bugs and makes collaboration smooth.Quiz
What appears between the opening `<!--` and closing `-->` of an HTML comment when viewed in the browser?
How would this HTML display in the browser: `<p>Hello world</p>`?
Alex wants to remember to add a contact form to their portfolio later. What's the best way to use a comment for this?
Up Next: Links and Navigation
Connect your pages together and build navigation menus that help users explore your website.