loading

HTML Comments

Html Comments, Html Source Code, Comment Tag, Hide Content, Inline Content

HTML comments can help you document your HTML source code even though they are not visible in the browser.


HTML Comment Tag

You can use the following syntax to add comments to your HTML source:

				
					<!-- Write your comments here -->

				
			

You’ll see that the start tag has an exclamation point (!) but the end tag does not.

Add Comments

You can add reminders and notifications to your HTML code using comments:

Example

				
					<!-- This is a comment -->

<p>This is a sentence.</p>

<!-- Remember to add additional information here -->

				
			

Hide Content

Content can be hidden using comments.

If you want to temporarily conceal content, this can be useful:

Example

				
					<p>This is a sentence.</p>

<!-- <p>This is another sentence </p> -->

<p>This is a sentence too.</p>

				
			

You can also hide more than one line. Everything between the <!-- and the --> will be hidden from the display.

Example

Hide a section of HTML code:

				
					<p>This is a sentence.</p>
<!--
<p>Look at this cool picture:</p>
<img decoding="async" border="0" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E" alt="Trullii" title="Html Comments 2" data-lazy-src="pic_trullii.jpg"><noscript><img decoding="async" border="0" src="pic_trullii.jpg" alt="Trullii" title="Html Comments 2"></noscript>
-->
<p>This is a sentence too.</p>
				
			

One of the best things about comments for debugging HTML is that you can search for mistakes by commenting out individual lines of code.

Hide Inline Content

Comments can be used to hide parts in the middle of the HTML code.

Example

Hide a part of a sentence:

				
					<p>This <!-- great text --> is a sentence.</p>
				
			

HTML

HTML5

HTML tutorials

Learn HTML

Free HTML tutorials

HTML Example

HTML Explained

HTML comments
HTML source code
comment tag
hide content
inline content

HTML comments are a powerful feature in HTML that allow developers to add notes, explanations, or temporary code within the source code of a web page. These comments are not visible to the end-user when the page is rendered in a web browser.

The HTML comment tag is denoted by the opening “ syntax. Anything written between these tags will be ignored by the browser and will not be displayed on the web page.

HTML comments can serve several purposes:

  1. Documenting the code: Developers can use comments to explain the purpose, functionality, or logic behind specific HTML elements or sections of the code. This makes the code more readable and maintainable, especially for collaborative projects or when revisiting the code later.
  2. Temporarily disabling code: Developers can use comments to “hide” certain HTML elements or sections of the code, allowing them to be easily re-enabled or removed later, without having to delete the code entirely.
  3. Debugging and troubleshooting: Comments can be used to isolate and identify issues in the HTML code by temporarily disabling or highlighting specific elements.
  4. Collaboration and communication: Comments can be used to leave notes, suggestions, or instructions for other developers or team members working on the same project.

By leveraging HTML comments, developers can improve the overall quality, organization, and maintainability of their web pages, making the development process more efficient and effective.

Share this Doc

HTML Comments

Or copy link

Explore Topic