<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML Comments Example</title>
</head>
<body>
<!-- This is a comment explaining the purpose of the page -->
<h1>Welcome to My Website</h1>
<!-- TODO: Add more content later -->
<p>This is a sample paragraph.</p>
<!--
Multi-line comments
can span across
multiple lines
-->
</body>
</html>
「Go Live」をクリックして Web サーバを開き、comments-example.html をクリックしてレンダリングされた Web ページを表示します。
これらのコメントは、レンダリングされた Web ページには表示されませんが、ページソースを見るときには表示されます。
単一行の HTML コメントを作成する
このステップでは、HTML コードの特定の部分を説明するための簡潔な注釈である単一行の HTML コメントを作成する方法を学びます。
単一行コメントは、HTML コメントの最も一般的なタイプです。特定の行やコードセクションについての簡単な説明や注釈を提供するために使用されます。単一行コメントを練習するために新しい HTML ファイルを作成しましょう。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Single-Line Comments Example</title>
</head>
<body>
<!-- This is a single-line comment describing the main heading -->
<h1>Welcome to My Web Page</h1>
<!-- Navigation menu section -->
<nav>
<ul>
<!-- Home link -->
<li><a href="#">Home</a></li>
<!-- About link -->
<li><a href="#">About</a></li>
<!-- Contact link -->
<li><a href="#">Contact</a></li>
</ul>
</nav>
<!-- Main content area -->
<main>
<!-- Paragraph with additional context -->
<p>This is an example of using single-line HTML comments.</p>
</main>
</body>
</html>
単一行の HTML コメントに関する要点:
<!-- で始まり、--> で終わります
簡単な説明や注釈を提供するために使用されます
HTML 要素の前または後に配置できます
Web ページのレンダリングに影響しません
コードの読みやすさと文書化に役立ちます
複数行の HTML コメントを作成する
このステップでは、より詳細な説明を提供するために役立つ複数行の HTML コメントを作成する方法、または一時的により大きなコードブロックを無効にする方法を学びます。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Multi-Line Comments Example</title>
</head>
<body>
<!--
This is a multi-line comment
demonstrating how to write
comments that span multiple lines.
You can include:
- Detailed explanations
- TODO notes
- Code documentation
- Temporary code blocks
-->
<h1>Welcome to My Web Page</h1>
<!--
Temporarily disabled section
<div class="hidden-content">
<p>This content is currently hidden using a multi-line comment.</p>
</div>
-->
<main>
<!--
Project Description:
This is a sample webpage to demonstrate
the use of multi-line HTML comments
in web development.
-->
<p>Learning HTML comments is an important skill for web developers.</p>
</main>
</body>
</html>
この実験では、参加者は HTML コメントと特殊文字を探り、HTML コードを効果的に文書化して注釈付けする方法を学びました。この実験では、HTML コメントの構文と使い方を学び、開発者が Web ページの閲覧者には見えないが、ソースコードを調べるときにアクセスできる説明的な注釈を追加できる方法を示しました。
参加者は、単一行と複数行のコメントの作成を練習し、<!-- で始まり --> で終わるなどの主な特徴を理解しました。また、コードの文書化、コードセクションを一時的に隠す方法、「TODO」マーカーのような開発ノートの追加にコメントをどのように使用するかを学びました。さらに、この実験では、特殊文字を表す HTML 文字エンティティを紹介し、HTML のテキストレンダリング機能の理解を深めました。