HTML for Web Development

0% completed

Previous
Next
HTML Comments

Comments are essential tools that help you explain your code, make notes, and organize your HTML documents without affecting how your web page is displayed.

What Are HTML Comments?

HTML comments are pieces of text that you can include in your HTML code to leave notes or explanations. These comments are not visible to users when they view your web page in a browser, but they are visible in the code itself. Comments are useful for:

  • Explaining Code: Helping you and others understand what different parts of your code do.
  • Organizing Code: Keeping your code tidy and easier to navigate.
  • Debugging: Temporarily hiding parts of your code without deleting them.

How to Write Comments in HTML

To create a comment in HTML, use the following syntax:

<!-- This is a comment -->

Breakdown:

  • <!-- : Starts the comment.
  • This is a comment : The content of the comment.
  • --> : Ends the comment.

Anything written between <!-- and --> will be treated as a comment and will not be displayed on the web page.

Single-Line Comment

<!-- This is a single-line comment -->

Multi-Line Comment

<!-- This is a multi-line comment. You can write comments that span multiple lines. -->

Using Comments in an HTML Document

Let's see how comments can be integrated into an HTML document.

HTML

. . . .

Explanation of the Example:

  • Paragraph Comment: The comment above the <p> tag describes the purpose of the paragraph.

    <!-- Introductory paragraph --> <p>This is an editable paragraph. Feel free to change this text!</p>
  • Image Comment: The image line is commented out. If you remove the <!-- and -->, the image will appear on the page.

    <!-- Uncomment the line below to add an image to your page --> <!-- <img src="your-image.jpg" alt="Your Image Description"> -->

Here, don't worry about how we have added image, we will learn it in upcoming chapters.

In the next chapter, we will learn about HTML elements.

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next