HTML Comments

Comments are an essential part of HTML; it helps to provide the details of what is written in the HTML source code. HTML comment tags are completely ignored to display by the browsers. It's used to insert comments into the source code.

  • When more than one developer works on the same application or web page, HTML comments can help understand the source code.
  • Comment can be used anywhere to add information about HTML, which will help developers easily understand the existing code in the future.

Writing Comments in HTML

For writing comments in HTML, they begin with the <! -- (starting comment tag) and ends with the close comment tag, i.e. -->. Comments in HTML can be visible if and only if anyone tries to view the source code of the page, but anything is written within <!-- …. --> does not get rendered when you will render your HTML based web page through your browser.

<!-- This is a commented code -->
<!DOCTYPE html>
    <title>Example for comment.</title>

<!-- Body of webpage starts from here -->
    <h2>This is HTML comment example</h2>
    <p>This is my first <strong>paragraph text</strong>.</p>

Scroll Back to Top