เว็บและ HTML

การอ้างอิงอักขระที่มีชื่อ

HTML entity ที่ใช้ชื่อที่อ่านง่าย: © → ©, — → — HTML5 กำหนด 2,231 การอ้างอิงแบบมีชื่อ และทั้งหมดคำนึงถึงตัวพิมพ์เล็ก-ใหญ่

· Updated

What Are Named Character References?

Named character references (also called named HTML entities) are predefined shorthand sequences that represent specific Unicode characters in HTML. They follow the pattern &name; where name is a case-sensitive keyword registered in the HTML specification. Examples include & for the ampersand character, < for the less-than sign, and © for the copyright symbol ©.

The HTML5 specification defines 2,231 named references, covering characters across many Unicode blocks: Latin letters with diacritics, Greek and Cyrillic letters, mathematical symbols, arrows, currency signs, playing card suits, and more.

History and Design

Named references were introduced early in HTML to help authors write documents using only ASCII source files while displaying richer character sets. Before UTF-8 became universal, a document might be saved in Latin-1 but still need to display Greek letters or typographic dashes. Named entities provided a portable solution.

HTML4 borrowed many entities from ISO character sets and SGML. HTML5 dramatically expanded the list by adding all characters from MathML and a large portion of common Unicode symbols.

The Five Essential Entities

Five named references are special because they escape HTML syntax characters:

&lt;    → <   (less-than, starts tags)
&gt;    → >   (greater-than, ends tags)
&amp;   → &   (ampersand, starts entities)
&quot;  → "   (double quote, used in attributes)
&apos;  → '   (apostrophe, HTML5 only; use &#39; for HTML4)

Forgetting to escape these — especially & and < in user-generated content — is the root cause of many XSS vulnerabilities.

Commonly Used Named References

<!-- Typography -->
&nbsp;    → non-breaking space (U+00A0)
&mdash;   → — (em dash, U+2014)
&ndash;   → – (en dash, U+2013)
&ldquo;   → " (left double quote)
&rdquo;   → " (right double quote)
&lsquo;   → ' (left single quote)
&rsquo;   → ' (right single quote, apostrophe)
&hellip;  → … (ellipsis)

<!-- Currency -->
&euro;    → € (U+20AC)
&pound;   → £ (U+00A3)
&yen;     → ¥ (U+00A5)
&cent;    → ¢ (U+00A2)

<!-- Math and science -->
&times;   → × (U+00D7)
&divide;  → ÷ (U+00F7)
&plusmn;  → ± (U+00B1)
&infin;   → ∞ (U+221E)
&sum;     → ∑ (U+2211)
&radic;   → √ (U+221A)
&pi;      → π (U+03C0)

<!-- Arrows -->
&larr;    → ← (U+2190)
&rarr;    → → (U+2192)
&uarr;    → ↑ (U+2191)
&darr;    → ↓ (U+2193)

Case Sensitivity

Named references are case-sensitive. &copy; works, &COPY; and &Copy; do not. A few names have uppercase variants that mean something different: &Alpha; is Α (Greek capital Alpha), while &alpha; is α (Greek small alpha).

Verifying Named References

// Decode a named entity by injecting into DOM
function decodeEntity(entity) {
  const el = document.createElement("textarea");
  el.innerHTML = entity;
  return el.value;
}

decodeEntity("&mdash;");   // "—"
decodeEntity("&hellip;");  // "…"
decodeEntity("&notaref;"); // "&notaref;" — unknown entities are left as-is

When to Use Named References Today

With UTF-8 encoding, you can paste ©, , and directly into HTML source. Named references are mainly useful for: code samples that must remain plain ASCII, generated HTML in environments where the encoding might shift, and developer readability when the intent matters (&nbsp; is clearer than a bare invisible space character).

Quick Facts

Property Value
Total defined in HTML5 2,231 named references
Case sensitivity Case-sensitive (&amp; valid, &AMP; invalid)
Must always escape &amp; &lt; &gt; &quot;
Trailing semicolon Required in most contexts; optional legacy exceptions exist
XML compatibility Only &amp; &lt; &gt; &quot; &apos; are predefined in XML
Browser behavior Unknown named references displayed as literal text

คำศัพท์ที่เกี่ยวข้อง

เพิ่มเติมใน เว็บและ HTML

CSS Text Direction

CSS properties (direction, writing-mode, unicode-bidi) controlling text layout direction. Works with Unicode …

HTML เอนทิตี

การแทนค่าอักขระในรูปแบบข้อความใน HTML สามรูปแบบ: ชื่อ (&amp;), ทศนิยม (&#38;), เลขฐานสิบหก (&#x26;) จำเป็นสำหรับอักขระที่ขัดแย้งกับไวยากรณ์ HTML

Internationalized Domain Name (IDN)

ชื่อโดเมนที่มีอักขระ Unicode ที่ไม่ใช่ ASCII เก็บไว้ภายในเป็น Punycode (xn--...) แต่แสดงเป็น Unicode ให้ผู้ใช้เห็น ความกังวลด้านความปลอดภัย: การโจมตีแบบ …

JavaScript Intl API

ECMAScript Internationalization API providing locale-aware string comparison (Collator), number formatting (NumberFormat), date …

Punycode

การเข้ารหัสที่เข้ากันได้กับ ASCII สำหรับชื่อโดเมน Unicode แปลงป้ายกำกับที่ถูก internationalize เป็นสตริง ASCII ที่มีคำนำหน้า xn-- münchen.de → …

Unicode in CSS

CSS supports Unicode via escape sequences (\2713 for ✓), the content property …

การอ้างอิงอักขระ XML

เวอร์ชัน XML ของการอ้างอิงอักขระเชิงตัวเลข: &#x2713; หรือ &#10003; XML มีเพียง 5 entity ที่มีชื่อ (&amp; …

การอ้างอิงอักขระเชิงตัวเลข

HTML entity ที่ใช้หมายเลข code point Unicode: ทศนิยม (&#169; → ©) หรือเลขฐานสิบหก (&#xA9; …

การเข้ารหัสเปอร์เซ็นต์ (URL encoding)

การเข้ารหัสอักขระที่ไม่ใช่ ASCII และอักขระที่สงวนไว้ใน URL โดยแทนที่แต่ละไบต์ด้วย %XX ใช้ UTF-8 ก่อน แล้วเข้ารหัส percent แต่ละไบต์: …

การแสดงข้อความ

การเรนเดอร์อักขระด้วย glyph ข้อความสีเดียวธรรมดาแทนที่จะเป็น emoji แบบสี มักใช้ Variation Selector 15 (U+FE0E) เพื่อแทนที่การแสดงผล emoji …