Do you know? HTML has its own HTML Comment tag, which you can use to add comments in your HTML document, similar to other programming languages. The HTML Comment tag makes your code readable and easy to interpret by anyone who tries to take a look at your HTML code.
HTML Comments make your code more readable and easier to interpret. Here, learn more about the HTML comment tag in detail.
What Is an HTML Comment Tag?
An HTML Comment tag is a bookmarking tag used to add or insert a note to the webpage. These tags are not rendered on the live webpage. They are only used for documentation purposes within the code.
When you add a comment to a tag like <heading>, <paragraph>, or any other, you make them more structured and user-friendly. This helps developers or anyone who is trying to read your code to better understand the complex code. Comments are most useful when you are debugging the code.
Read More: 10 CSS Tricks for UI Developers: Scale User Designing And Front End Development In 2025
HTML Comment Tag: Key Takeaways
Let us quickly check some of the major facts about HTML Comment tags used for web pages.
- The HTML Comment tag supports both single as well as multiple lines.
- An HTML Comment tag starts with <!– and ends with –> tag.
- The browser ignores the comment part when it renders the coding part. Hence, they are not visible on the live page.
- HTML Comments can only be used as content and not within a tag.
- A comment is not an HTML element, whether it starts with a < and ends with a > tag.
HTML Comment Tag Syntax
The HTML comment tag inserts notes or explanations to the code that are not executed in the live browser.
| <!- – This is comment – -> |
The text you enter within the <!- – and – – > is ignored by the browser and is not executed. You can add multiline comments in HTML. Check the syntax for Multiline Comments in HTML
Multiline HTML Comment Tag
| <!–
This is a multi-line comment. It can be used to explain sections of your HTML. –> |
Example of HTML Comment Tag
Let us understand the HTML Comments with the help of a simple example given below.
| <!DOCTYPE html>
<html> <head> <title>HTML Comment Example</title> </head> <body> <!– This is the header section –> <h1>Welcome to My Website</h1> <!– This paragraph describes the website –> <p>This website is about learning HTML basics.</p> <!– The following line is temporarily hidden –> <!– <p>This text will not be shown on the webpage.</p> –> <!– Footer Section –> <footer> <p>© 2025 MyWebsite</p> </footer> </body> </html> |
Output
![]() |
Everything enclosed within the HTML comment syntax is ignored by the website and makes the code more readable. You can see the output; no comment lines are added in the output.
Read More: Top 30 HTML Interview Questions and Answers 2025
Why Use Comment Tags In HTML?
HTML Comment tags make your code clearer and easier to maintain and debug. Using comments in code is a good practice as it helps developers express each part of the code in a more user friendly way.
- HTML Comment tags are used to add notes or explanations, which can be used to understand any specific part of code.
- They divide large HTML pages into multiple sections, organizing them in a proper manner.
- You can also use HTML comments to temporarily disable a part of your code without having to delete it permanently.
- Comments make it easier for teams to collaborate and communicate by making code user friendly.
- It also acts as your personal To Do which you can revisit at any later part.
Do you know, even when browsers do not execute the HTML comments, you can view them using the browser’s “View Source” feature.
Where To Use the HTML Comment Tag?
You can use HTML comments almost anywhere inside an HTML document.
- You can add HTML comments before or after the Doctype
- Also, add it before and after the <html> comments
- You can use HTML comments as the content for most tags, except tags like <style>, <script>, <title>, <textarea>, and more.
Also, you can use comments to document, organize or debug code anywhere inside the HTML document.
HTML Tags Inside Comments
When you enclose your code inside a comment tag, your code will be ignored by the browser during rendering or execution. For example, check it below.
| <p> This line will get executed by the browser </p>
<!– <p> This line will not get executed or displayed by the browser–> <p>This line will also get executed by the browser. </p> |
Output
![]() |
Are There Any Shortcuts for Adding an HTML Comment Tag?
Many coding platforms leverage coders with the ability to use keyboard shortcuts to attach comments with a tag in HTML. You can insert an HTML comment tag on your Windows or macOS device by using the following keyboard shortcut.
- Ctrl + / (For Windows)
- Cmd + / (For macOS)
These shortcuts will help you get your comment game stronger and encourage YouTube to add an extra set of information or temporarily keep aside a certain part of the code.
Read More: A Href Tag in HTML: Everything You Need to Know About Them!
Example of Multiline HTML Comments
You can use the HTML Comment tag to add multiline comments in your code.
| <!DOCTYPE html>
<html> <head> <title>HTML Comment Tag Example – PW Skills</title> </head> <body> <h2>Welcome To PW Skills</h2> <p>Example of Multiline Comment in HTML</p> <!– <p>This content is commented out for now.</p> <p>It might be added later when the page is updated.</p> <p>Comments help developers at PW Skills organize their code.</p> –> </body> </html> |
Output
![]() |
Everything you enclosed between the <!– and –> tags is not displayed by the browser. You can use them to hide or document multiple lines of code.
Learn Everything About HTML With PW Skills
Master HTML, CSS, Javascript, and all major aspects of web development with PW Skills Full Stack Web Development course. Get interactive coursework and real world projects to strengthen your understanding of the complete development.
Learn about the fundamentals of HTML, important tags, and the best ways to use them in your project. Get 24×7 doubt support, practice exercises, real world projects, assignments, and more.
After completion, you will get an industry recognised certification by PW Skills to level up your game in web development and gain exposure.
HTML Comment Tag FAQs
Q1. What is an HTML Comment Tag?
Ans: An HTML comment tag is used to add notes or explanations to code and make it more readable and understandable for developers or teams.
Q2. What is the syntax of the HTML Comment tag?
Ans: The comment tag in HTML is defined using the tags. Everything enclosed within these two tags is not executed by the browser.
Q3. Why use HTML Comment tags?
Ans: An HTML Comment tag makes your code more readable, helping you better understand or debug a part of the code. Also, you can conduct trials by commenting out a part of the code as per your needs.
Q4. Are HTML comments executed by the compilers?
Ans: No, HTML comments are not displayed or executed by the compilers as they are only used for documentation purpose.



