HTML Comment Tag
Comments in HTML have the same role as in any programming language.
They can help to describe a section of the code, to explain what that section does.
HTML Comments Syntax
<!-- HTML comments here -->
Example
<!DOCTYPE html> <html> <body> <!-- Start paragraph here --> This is my first paragraph. This is my second paragraph. <!-- End paragraph here --> <a href="https://www.oixiesoft.com/">Visit Oixiesoft.com!</a> </body> </html>
Output
This is my first paragraph.
This is my second paragraph.
Hide Content
Sometimes Html comments can be used to hide an entire piece of code.
For example, we have a section of code that no longer uses us, but we don’t want to delete it either. So we can hide this section with the help of comments.
Never comment on passwords or other confidential information in HTML or CSS. Even if the comments are not displayed in the browser, they appear in the source of the page loaded in the browser.
Example1
<!DOCTYPE html> <html> <body> <p>This is my first paragraph.</p> <!-- <p>This is my second paragraph.</p> --> <a href="https://www.oixiesoft.com/">Visit Oixiesoft.com!</a> </body> </html>
Output
This is my first paragraph.
Example 2
<!DOCTYPE html> <html> <body> This is my first paragraph. This is my second paragraph. <!-- <img src="https://www.oixiesoft.com/wp-content/uploads/2022/04/Porcelain-Espresso-Cups-.jpg" /> --> </body> </html>
Output
This is my first paragraph.
This is my second paragraph.
This is my second paragraph.