On-Page SEO

Comments Tag

Shahid Maqbool

By Shahid Maqbool
On Jul 4, 2023

Comments Tag

What is a Comments Tag?

A comments tag is a piece of code used in HTML and other programming languages to include non-executable text within the code.

These comments are text-based annotations that developers add to their code to provide additional information or to explain certain parts of the code.

In HTML, the comments tag is written like this:

<!-- This is a comment -->

Anything within the opening and closing comment tags will not be rendered by the browser.

This means that comments can be used to add notes, reminders, or explanations to the code without affecting the appearance or functionality of the web page.

In other programming languages such as JavaScript, PHP, and CSS, comments can be added using different syntax, but the purpose is the same - to provide additional context and understanding to the code for developers who may need to work on it in the future.


The syntax of the comments tag in HTML is quite simple. It consists of two parts:

  • an opening comment tag <!--  

  • a closing comment tag -->.

Anything that appears between these two tags will be treated as a comment and will not be rendered by the browser.

Here is an example of the syntax of an HTML comment tag:

<!-- This is a comment for the developer -->

In this example, the comment text is "This is a comment for the developer ". This text will not be visible on the webpage when it is rendered in the browser.

Instead, it will only be visible in the HTML code when viewed in a text editor or developer console.

Why are comments tag important?

Comments tags are important in web development for several reasons:

Code documentation

Comments can provide useful information about how the code works, what it does, and why it was implemented that way.

This can be very helpful for other developers who need to work on the code later, as well as for the original developer who may need to revisit the code in the future.


Comments can be used to temporarily remove sections of code for testing or debugging purposes without actually deleting them.

This can help identify and fix bugs more quickly, without having to rewrite entire sections of code.


Comments can be used to communicate with other developers who may be working on the same project, providing useful insights or suggestions for improvements.


Comments can also help make web content more accessible for people with disabilities, such as those using screen readers.

By providing descriptive comments for images and other non-text content, developers can ensure that users with visual impairments can understand the content of the page.

It is important to note that comments should not be used excessively, as they can clutter up the code and make it harder to read.

However, judicious use of comments can help to explain complex code or provide context for other developers who may need to work on the code in the future.

How to add HTML comments tag?

To add an HTML comment tag to your code, follow these steps:

  1. Open your HTML file in a text editor, such as Notepad or Sublime Text.

  2. Navigate to the section of code where you want to add the comment.

  3. Type <!-- to open the comment tag.

  4. Type your comment text.

  5. Type --> to close the comment tag.

For example, if you want to add a comment above a section of code that sets the background colour of a webpage, you could add the following comment tag:

<!-- This section sets the background colour of the webpage -->

<body style="background-color: #f2f2f2;">

When you save your HTML file and view it in a web browser, the comment will not be displayed on the webpage itself.

Instead, it will only be visible in the code when viewed in a text editor or developer console.

Keyboard shortcuts for adding comments tags

When writing code, it is often useful to add comments to explain what the code does or to provide additional information for other programmers. However, typing out comment tags can be time-consuming.

To save time, many code editors and integrated development environments (IDEs) provide keyboard shortcuts for quickly adding comments to code.

One of the most common shortcuts is Ctrl + / on a PC or Command + / on a Mac.

When you select a line of code and press this shortcut, the code editor will automatically insert the appropriate comment tags to comment out the line.

This method is much faster than typing out the tags manually, especially if you need to comment out multiple lines of code at once.

Types of comments tag

There can be two types of comments tag.

Single-line comment

These are used to comment on a single line in the code. In many programming languages, a single-line comment starts with two forward slashes (//).

Any text following the slashes on the same line will be considered a comment. However, in HTML, there is no specific single-line comment syntax, and the standard comment tag is used.

For example, in JavaScript:

// This is a single-line comment


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

Multi-line comment

These are used to comment on multiple lines in the code. In several programming languages, a multi-line comment starts with a forward slash and an asterisk (/) and ends with an asterisk and a forward slash (/).

In HTML, multi-line comments start with "<!--" and end with "-->".

For example, in JavaScript:


This is a

multi-line comment




This is a multi-line

comment in HTML


How did comments tag affect SEO in past?

In the past, some webmasters attempted to manipulate search engine rankings through a Black Hat SEO tactic involving HTML comment tags.

They would "stuff" these comment tags with numerous keywords, hoping that search engines would take these hidden keywords into account when indexing and ranking their pages.

The goal was to make the webpage appear more relevant to those keywords, thereby improving its search engine ranking.

However, this strategy proved to be ineffective and counterproductive. Modern search engines like Google have advanced algorithms that can detect and penalize such deceptive tactics.

Keyword stuffing, whether in visible text or hidden in comment tags, can result in a website being downgraded in search rankings or even removed from search results entirely.

Therefore, even in the past, while some tried to use comment tags to influence SEO, it was neither an ethical nor effective strategy.

It is always best to adhere to good SEO practices, such as creating high-quality, relevant content, and optimizing your pages in a user-focused manner.

Ending note

Comment tags, while a fundamental part of web development, do not directly influence SEO.

They are designed to provide clarity for developers, not to be seen by users or indexed by search engines.

In the past, webmasters tried to manipulate SEO by stuffing comment tags with keywords, a practice known as Black Hat SEO.

However, modern search engines have evolved and are designed to penalize such tactics.

Related Articles

Leave a reply
All Replies (0)