Encode special characters to numeric HTML entities (<, ©) and decode back
Convert reserved HTML characters (`<`, `>`, `&`, `"`, `'`) and non-ASCII symbols (`©`, `₹`) into decimal numeric character references (`&#...;`) or decode HTML entities back to plain text.
In HTML documents, characters such as `<`, `>`, `&`, `"`, and `'` have special syntactic meanings: `<` and `>` open and close markup tags, `&` begins an entity reference, and quotes delimit tag attributes. If you want to display raw code snippets (like `<div class="header">`) or special symbols as literal visible text on a webpage without the browser interpreting them as live HTML tags, you must convert those characters into HTML character references. Our HTML Entity Encoder & Decoder provides two instant client-side actions: 'Encode to HTML Entities' and 'Decode Entities to Text'.
Understanding how the encoder and decoder work in this tool ensures predictable results. When you click 'Encode to HTML Entities', the tool scans your input using the regular expression `/[\u00A0-\u9999<>&"']/g` and replaces every matched character with its decimal numeric character reference `&#N;`, where `N` is the character's Unicode code point (`c.charCodeAt(0)`). For example, `<` becomes `<`, `>` becomes `>`, `&` becomes `&`, `"` becomes `"`, `'` becomes `'`, and the copyright symbol `©` becomes `©`. When you click 'Decode Entities to Text', the tool parses the string through the browser's `DOMParser().parseFromString(entityText, "text/html")` and extracts `doc.documentElement.textContent`, which cleanly resolves both numeric references (`<`, `<`, `©`) and standard named entities (`<`, `>`, `&`, `"`, `©`) back into readable characters.
Practical Usage & Security Scope: Encoding `<`, `>`, `&`, `"`, and `'` into numeric entities is ideal when preparing code examples to paste inside HTML `<pre><code>` blocks or escaping special Unicode symbols (`©`, `®`, `₹`) so they render consistently even if a legacy web server misconfigures its character encoding header. However, keep two technical caveats in mind: first, if you click 'Decode Entities to Text' on input that contains unencoded HTML tags (like `<b>Hello</b>`), `DOMParser`'s `textContent` property will strip the raw `<b>` tags and output only `Hello` ( whereas encoded `<b>Hello</b>` decodes to literal `<b>Hello</b>`); second, HTML entity encoding alone is NOT a complete XSS sanitizer—never place untrusted user input inside `href="javascript:..."`, `<script>` blocks, or inline event handlers (`onload=`, `onclick=`) relying solely on entity encoding.
किसी भी HTML वेबपेज में `<`, `>`, `&`, `"` और `'` जैसे चिन्हों का विशेष तकनीकी अर्थ होता है: `<` और `>` नए HTML टैग को शुरू और बंद करते हैं, `&` किसी एंटिटी कोड की शुरुआत दर्शाता है, और कोट्स (`"`, `'`) एट्रिब्यूट की वैल्यू को घेरते हैं। यदि आप अपने वेबपेज या ब्लॉग पोस्ट पर `<div class="header">` जैसा कोई कोड उदाहरण के रूप में दिखाना चाहते हैं और चाहते हैं कि ब्राउज़र उसे असली HTML टैग समझने के बजाय स्क्रीन पर सामान्य टेक्स्ट की तरह दिखाए, तो उन चिन्हों को 'HTML Entities' में बदलना पड़ता है। हमारा HTML Entity Encoder & Decoder इसके लिए दो बटन प्रदान करता है: `Encode to HTML Entities` और `Decode Entities to Text`।
इस टूल की कार्यप्रणाली को समझना डेवलपर्स के लिए बहुत उपयोगी है। जब आप `Encode to HTML Entities` बटन पर क्लिक करते हैं, तो यह टूल `/[\u00A0-\u9999<>&"']/g` पैटर्न की मदद से सभी आरक्षित चिन्हों (`<`, `>`, `&`, `"`, `'`) और गैर-ASCII यूनिकोड अक्षरों (जैसे `©`, `₹`) को उनके दशमलव न्यूमेरिक कैरेक्टर रेफरेंस (`&#N;`, जहाँ `N` उसका यूनिकोड कोड पॉइंट `charCodeAt(0)` है) में बदल देता है। उदाहरण के लिए, `<` बदलकर `<` हो जाता है, `>` बदलकर `>`, `&` बदलकर `&`, `"` बदलकर `"`, `'` बदलकर `'` और `©` बदलकर `©` हो जाता है। वहीं जब आप `Decode Entities to Text` पर क्लिक करते हैं, तो टूल ब्राउज़र के `DOMParser().parseFromString(..., "text/html")` का उपयोग करके `textContent` निकालता है, जो न्यूमेरिक एंटिटी (`<`, `©`) और नेम्ड एंटिटी (`<`, `>`, `&`, `©`) दोनों को वापस सामान्य टेक्स्ट में डिकोड कर देता है।
व्यावहारिक उपयोग और तकनीकी सावधानियां: जब आपको किसी आर्टिकल के `<pre><code>` ब्लॉक के अंदर HTML कोड का उदाहरण दिखाना हो, तो उसे पहले यहाँ एनकोड कर लेने से ब्राउज़र उस कोड को रन नहीं करता। हालांकि, दो तकनीकी बातों का विशेष ध्यान रखें: पहली, यदि आप बिना एनकोड किए हुए सीधे HTML टैग्स (जैसे `<b>नमस्ते</b>`) पर `Decode Entities to Text` बटन दबाएंगे, तो `DOMParser` का `textContent` उन सीधे टैग्स को हटाकर केवल `नमस्ते` टेक्स्ट निकालेगा (जबकि एनकोड किए गए `<b>` या `<b>` को डिकोड करने पर पूरा `<b>` टैग टेक्स्ट के रूप में मिलेगा); दूसरी, केवल HTML एंटिटी एनकोडिंग को पूर्ण XSS सुरक्षा या HTML सैनिटाइज़र (Sanitizer) न मानें—विशेषकर `<script>` टैग या `onclick`/`href` एट्रिब्यूट्स के अंदर अनजान यूज़र इनपुट को बिना प्रॉपर सैनिटाइज़ेशन के कभी न डालें।