Skip to content

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

648 people viewed this

HTML Comments & Characters

<p>Version&nbsp;2.0</p>

This can keep short units or related tokens together in some contexts. However, do not use repeated non-breaking spaces to create page layout or large gaps. Use CSS for layout and spacing.

Typographic Dashes

<p>Use an en dash for a range: 2025&ndash;2026.</p>

<p>Use an em dash for a break in a sentence&mdash;like this.</p>

These references are optional when you can enter the actual punctuation characters directly.


11. Character References in Attributes

Character references can also be used in attribute values. This is especially useful when an attribute value needs to contain a character that would otherwise interfere with the markup syntax.

Example: Quotation Mark in an Attribute Value

<input
  type="text"
  value="He said &quot;Hello&quot;"
  aria-label="Example quotation"
>

The input's value contains quotation marks around the word Hello.

Example: Ampersand in a URL Attribute

<a href="search.php?topic=html&amp;page=2">
  Search results
</a>

In the HTML source, &amp; represents the ampersand character in the URL value. When the browser parses the attribute, the URL contains the ampersand separator.

When you generate URLs programmatically, use the appropriate URL-building and HTML-escaping functions for the context. HTML character references and URL encoding solve different problems.


12. HTML Character References vs CSS and JavaScript Escapes

Different technologies use different escape mechanisms. Do not assume that a character escape in one language has the same meaning in another.

HTML Character Reference

<p>Copyright &copy; 2026</p>

The browser interprets &copy; as the copyright symbol in HTML text.

CSS Escape

<style>
  .copyright::after {
    content: "\00A9";
  }
</style>

<p class="copyright">2026 Codementrix</p>

In CSS, the escape \00A9 represents the copyright symbol in the CSS string. CSS escape syntax is different from HTML character-reference syntax.

Rate this course

5.0 · 1 rating

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

Your stars