HTML Comments: How to Comment Out your HTML Code

The comment tag is an element used to leave notes, mostly related to the project or the website. This tag is frequently used to explain something in the code or leave some recommendations about the project. The comment tag also makes it easier for the developer to come back and understand the code he’s written at a later stage. Comments can also used for commenting out lines of code for debugging purposes.
It is good practice to add comments to your code, especially when working with a team or at a company.
Comments are started with <!— and ended with —> , and can span multiple lines. They can contain code or text, and won’t appear on the front-end of the website when a user visits a page. You can view comments through the Inspector Console, or by viewing Page Source.
Example
Conditional Comments
Conditional Comments defines some HTML tags to be excuted when a certain codition is fullfilled.
Conditional Comments are only recognised by Internet Explorer Version 5 through to Version 9 — IE5 — IE9.
Example
IE Conditional Comments
These comments are only available in Internet Explorer and can be used up to IE9. In the current times, there is a good change you will never see them, but it is good to know about their existance. Conditional comments are a way to serve a different experience for different client browsers. For example:
HTML, как добавить комментарий
Чтобы добавить комментарий в HTML документ, используют специальный тег <!— comment —> .
Комментарии — это текст, который будет виден твоим коллегам, но не будет виден пользователям, загрузившим веб-страницу.
Или ты просто хочешь оставить себе напоминание, о том, что должно быть сделано.
Причин для таких сообщений довольно много, но все эти сообщения объединяет то, что они не должны отображаться на странице, а видны только в редакторе кода, который ты используешь.
Для комментариев не нужны специальные теги, но их нужно как-то обозначить чтобы было понятно, где начало комментария и где его окончание.
HTML комментарий из одной строки
Простейший комментарий состоит из одной строки. Текст нужно разместить между последовательностью символов <!— и —> :
Обрати внимание, что восклицательный знак ставится только в начале, но не в конце тега.
HTML комментарий из нескольких строк
Если тебе нужно добавить длинный комментарий, который состоит из нескольких строк, это тоже можно сделать в HTML.
Если внутри комментария будут расположены какие-то HTML теги, то их на странице видно не будет.
Ошибки
Ошибки в HTML комментариях чаще всего связаны с лишним пробелом или пропущенным восклицательным знаком:
Оба комментария написаны неправильно и будут отображаться на HTML странице.
How to comment/uncomment in HTML code
Often while coding view templates in html, my habit of adding some helpful comments causes lots of time-consuming effort while testing.
Consider this code.
Now, if I have to hide out some portion of the view template, in case of php I would just select the desired code and put single-line comments (using a shortcut key most of the times).
However, in html code, where only the block comments work, I end-up removing all the closing comment tags (—>) till the position I want the commenting to occur — something like this.
Then when I’m done testing I have to go through the agony of putting back those closing tags.
Is there a better and time saving way of block commenting in HTML?
11 Answers 11
Yes, to comment structural metadata out,
Using <script>/* . */</script> in .html
Comment out large sections of HTML (Comment Out Block)
my personal way in a .html file is opening: <script>/* and close it with */</script>
<script>/* hiding code go here */</script>
Is a workaround to the problem since is not HTML.
Considering your code in .html.
And in a case is HTML inside PHP file using comment tag <?/* or <?php /* and close it with */?> . Remember that the file must be .php extension and don’t work in .html.
<?/* hiding code go here */?>
Considering your code in .php.
Is worth nothing that is not HTML but a common developer practice is to comment out parts of metadata so that it will not be rendered and/or executed in the browser. In HTML, commenting out multiple lines can be time-consuming. It is useful to exclude pieces of template structural metadata containing comments, CSS or code and systematically commenting out to find the source of an error. It is considered a bad practice to comment blocks out and it is recommended to use a version control system. The attribute "type" is required in HTML4 and optional in HTML5.