Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Using HTML comments <!-- … -->

An HTMLcomment is used to add explanatory notes to the markup or to prevent the browser from interpreting specific parts of the document.

Comments start with the string<!-- and end with the string-->, generally with text in between. This text cannot start with the string> or->, cannot contain the strings--> or--!>, nor end with the string<!-, though<! is allowed.

The browser ignores comments as it renders the code. In other words, they are not visible on the page - just in the code. HTML comments are a way for you to write helpful notes about your code or logic.

The above is true forXML comments as well. In addition, in XML, such as inSVG orMathML markup, a comment cannot contain the character sequence--.

Comments can be used on a single line, or span multiple lines. They can be used in the following places:

Note:While<script> elements should not have HTML comments and should useJavaScript comments instead, there was a legacy practice to enclose the whole script content in an HTML comment so ancient browsers that don't support JavaScript don't render it as text. This is now alegacy feature of JavaScript itself and you should not rely on it.

Syntax

html
<!-- Comment -->

Examples

html
<!-- A one-line comment --><!--A commentthat stretchesover severallines--><!-- The comment below disables   the HTML contained within --><!--<p>   This content will not be rendered.</p>-->

Notes

HTML comments are only permitted as content. You cannot use it within a tag, such as before an HTMLattribute.

As with most programming languages that use the<!-- --> comment syntax, comments cannot be nested. In other words, the first instance of--> that follows an instance of<!-- closes the comment.

While comments do start with a< and end in a>, a comment is not an HTML element.

Specifications

Specification
HTML
# comments

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp