CKTIS / HTML
HTML comments: `<!--` and `-->`
HTML comments let you leave notes in the source or temporarily disable a piece of markup without deleting it. Browsers do not display comments on the page, but readers can still find them in the source.
Version: HTML Living Standard
Syntax
<!-- comment text -->The Polish phrase komentarze HTML <!-- --> means HTML comments. A comment opens with <!-- and closes with -->. It can contain one line, several lines, or no text at all. Use comments to explain why markup is written a certain way or to temporarily disable a piece of markup.
The browser does not display the comment. Any markup inside it remains comment text and does not create elements. The comment itself is a Comment node in the DOM, not an HTML element. It is readable in the page source, so never put passwords or other confidential information in a comment.
You can put a comment between paragraphs, for example, but not inside a start tag or an attribute value. In title and textarea, these delimiters do not create HTML comments. For JavaScript in script and CSS in style, use the comment syntax of the respective language.
Do not nest comments. Comment text cannot start with > or ->, contain <!--, -->, or --!>, or end with <!-. HTML does not ban -- on its own, but XML syntax does.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML comments</title>
</head>
<body>
<!-- This note is for people reading the source. -->
<p>Visible paragraph.</p>
<!--
<p>Commented-out paragraph.</p>
-->
</body>
</html>Result
Visible paragraph.
The page should show only `Visible paragraph.`. View the page source to find the note and the commented-out paragraph. In the DOM, the second paragraph's markup is part of a comment, not a separate `p` element.
Related lessons
- HTML · Lesson 33 · Basic · Version: 2