Skip to content

Courses / HTML5 Mastery: Complete Beginner to Advanced Course / HTML Comments & Characters

549 people viewed this

HTML Comments & Characters

<!-- Outer comment
  <!-- Inner comment -->
Outer comment continues -->

This is not a reliable way to create nested comments. The inner closing delimiter can terminate the outer comment unexpectedly, causing malformed markup or unexpected visible text.

Use a single comment instead:

<!-- Notes about the course section go here. -->

Comments and Security

Comments are not a security boundary. A user can inspect the source delivered to their browser. Never put secrets, passwords, private tokens, internal credentials, or sensitive personal information in HTML comments.

Best practice: Write comments that explain why code exists when the purpose is not obvious. Avoid comments that merely repeat what the code already says.


3. What Are Special Characters in HTML?

Some characters have a special meaning in HTML markup. For example, angle brackets identify tags, while the ampersand begins a character reference in relevant contexts.

Consider this text:

5 < 10

If you want to display the less-than symbol as text inside ordinary HTML content, use a character reference:

<p>5 &lt; 10</p>

The browser displays:

5 < 10

Similarly, to display a greater-than symbol, you can use &gt;. To display an ampersand, use &amp;.

Common HTML Character References

Character HTML reference Common use
< &lt; Display a less-than sign
> &gt; Display a greater-than sign
& &amp; Display an ampersand
" &quot; Display a double quotation mark
' &apos; Display an apostrophe
Non-breaking space &nbsp; Prevent a line break at that space
© &copy; Copyright symbol
® &reg; Registered trademark symbol
™ &trade; Trademark symbol
€ &euro; Euro currency symbol
— &mdash; Em dash
– &ndash; En dash

HTML defines many more named character references. Use them when they improve readability or when the character would otherwise conflict with HTML syntax.


4. Named Character References

A named character reference uses a predefined name that begins with an ampersand and usually ends with a semicolon.

Syntax

Rate this course

5.0 · 1 rating

Stars show on this course. Your written note stays private.

Your stars