Stax
Tools

HTML Entity Encoder / Decoder

Encode HTML special characters to entities or decode entities.

Common HTML entities reference
CharEntityCharEntity
&&amp;<&lt;
>&gt;"&quot;
'&#39; &nbsp;
©&copy;®&reg;
&trade;&euro;
£&pound;¥&yen;
¢&cent;§&sect;
°&deg;±&plusmn;
×&times;÷&divide;
¼&frac14;½&frac12;
¾&frac34;&ndash;
&mdash;&lsquo;
&rsquo;&ldquo;
&rdquo;&bull;
&hellip;&larr;
&rarr;&uarr;
&darr;&harr;
&spades;&clubs;
&hearts;&diams;

5 อักขระ HTML จำเป็นที่ต้องเข้ารหัสเสมอ

สามโหมดการเข้ารหัสที่อธิบาย

การถอดรหัส HTML entities

ข้อความใดก็ตามที่จะแสดงผลเป็นเนื้อหา HTML ต้องใช้อักษร escape สำหรับอักขระห้าตัวนี้เพื่อป้องกันปัญหาการ parse และการโจมตี XSS:

สลับไปโหมด Decode เพื่อแปลง HTML entities กลับเป็นอักขระที่อ่านได้ มีประโยชน์สำหรับการอ่านซอร์สโค้ด HTML ตรวจสอบเนื้อหาอีเมลที่ถูกเข้ารหัส หรือประมวลผลข้อมูลที่เข้ารหัส HTML จาก API

นักพัฒนา backend ใช้ encoder เพื่อฆ่าเชื้อข้อมูลฟอร์มที่ผู้ใช้ส่งก่อนเขียนลง HTML template เพื่อป้องกันช่องโหว่ XSS ทีม Content วาง draft บล็อกเพื่อเข้ารหัสอักขระพิเศษก่อนเผยแพร่ วิศวกร front-end ใช้โหมด Decode อ่านการตอบสนอง API ที่ส่งคืนสตริงที่เข้ารหัส HTML

  • & (ampersand) → &amp;
  • &lt; (less than) → &lt;
  • &gt; (greater than) → &gt;
  • &quot; (double quote) → &quot;
  • ' (single quote) → &#39;
  • Minimal: เข้ารหัสเฉพาะ 5 อักขระพิเศษ HTML ด้านบน ใช้เมื่อแสดงเนื้อหาผู้ใช้ใน HTML เพื่อป้องกัน XSS
  • Named entities: แปลงอักขระที่มีชื่อ (©, ®, €, →) เป็น HTML entity เทียบเท่า มีประโยชน์สำหรับ HTML ที่ถูกต้องทางการพิมพ์
  • Numeric: เข้ารหัสอักขระที่ไม่ใช่ ASCII ทั้งหมดเป็นการอ้างอิงอักขระฐานสิบ (&#xx;) ใช้เมื่อกำหนดเป้าหมายเอกสาร HTML ที่เป็น ASCII เท่านั้น

คำถามที่พบบ่อย

What are HTML entities?
HTML entities are special codes used to represent characters that either have special meaning in HTML or cannot be typed easily. They start with an ampersand (&amp;) and end with a semicolon (;). For example, &lt; represents < (which would otherwise start an HTML tag) and &amp; represents &amp; (which would otherwise start an entity).
When do I need to encode HTML characters?
Encode HTML characters when: (1) displaying user-submitted content in HTML to prevent XSS (Cross-Site Scripting) attacks — any < > &amp; " ' must be encoded, (2) including special symbols like copyright ©, registered ®, or currency signs in HTML, (3) placing HTML code examples inside a web page for display.
What is the difference between named and numeric entities?
Named entities use a descriptive name: &lt; for <, &amp;copy; for ©. Numeric entities use the character's decimal (&#60;) or hex (&amp;#x3C;) Unicode code point. Named entities are more readable; numeric entities work for any character, even those without a named equivalent. All browsers support both.
What is XSS and how does encoding prevent it?
Cross-Site Scripting (XSS) is an attack where malicious JavaScript is injected into a web page via unescaped user input. If a user submits <script>alert(1)</script> and it is rendered as HTML, the script executes. Encoding the < and > as &lt; and &gt; makes the browser display the text literally instead of executing it as HTML.
What is the minimal encoding level?
Minimal encoding only escapes the 5 characters with special meaning in HTML: &amp; (→ &amp;), < (→ &lt;), > (→ &gt;), " (→ &quot;), and ' (→ &#39;). This is the minimum required to safely embed text in HTML and prevent XSS. Use this level when you need to display user input in an HTML page.

เครื่องมือที่เกี่ยวข้อง