HTML Entity Encoder / Decoder
Encode HTML special characters to entities or decode entities.
Common HTML entities reference
| Char | Entity | Char | Entity |
|---|---|---|---|
| & | & | < | < |
| > | > | " | " |
| ' | ' | | |
| © | © | ® | ® |
| ™ | ™ | € | € |
| £ | £ | ¥ | ¥ |
| ¢ | ¢ | § | § |
| ° | ° | ± | ± |
| × | × | ÷ | ÷ |
| ¼ | ¼ | ½ | ½ |
| ¾ | ¾ | – | – |
| — | — | ‘ | ‘ |
| ’ | ’ | “ | “ |
| ” | ” | • | • |
| … | … | ← | ← |
| → | → | ↑ | ↑ |
| ↓ | ↓ | ↔ | ↔ |
| ♠ | ♠ | ♣ | ♣ |
| ♥ | ♥ | ♦ | ♦ |
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) → &
- < (less than) → <
- > (greater than) → >
- " (double quote) → "
- ' (single quote) → '
- 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 (&) and end with a semicolon (;). For example, < represents < (which would otherwise start an HTML tag) and & represents & (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 < > & " ' 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: < for <, &copy; for ©. Numeric entities use the character's decimal (<) or hex (&#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 < and > 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: & (→ &), < (→ <), > (→ >), " (→ "), and ' (→ '). 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.
เครื่องมือที่เกี่ยวข้อง
- JSON Formatter, Validator & Repair Tool
Format, minify, validate, and repair JSON instantly in your browser. Sort keys alphabetically, auto-format on paste, download as file, escape/unescape strings — free, no sign-up, 100% client-side.
- ตัวสร้าง QR Code
สร้าง QR code สำหรับ URL ข้อความ Wi-Fi และอื่นๆ ดาวน์โหลดเป็น PNG
- ตัวสร้างรหัสผ่าน
สร้างรหัสผ่านสุ่มที่แข็งแกร่งด้วยความยาวและชุดอักขระที่กำหนดเอง
- Base64 เข้ารหัส / ถอดรหัส
เข้ารหัสข้อความเป็น Base64 หรือถอดรหัสกลับเป็นข้อความธรรมดา
- URL เข้ารหัส / ถอดรหัส
เข้ารหัสหรือถอดรหัส URL และ query strings ด้วย percent-encoding