ASCII to HTML Converter
Convert ASCII text to HTML entities instantly. Supports named, decimal, and hexadecimal encoding with selective or full character conversion.
About
Incorrect character encoding breaks web pages. An unescaped & in HTML source triggers parse errors. A raw < opens an unintended tag. These are not cosmetic issues - they cause content loss, XSS vulnerabilities, and validation failures against the W3C HTML specification. This converter processes each character at code point c in the range 0 - 255 and outputs its correct HTML entity reference: named (e.g., &) when one exists in the HTML5 named character reference table, or numeric (decimal &#c; or hexadecimal ) otherwise.
Two modes are provided. Selective mode encodes only the 5 mandatory characters (&, <, >, ", ') plus non-ASCII bytes - sufficient for valid HTML output. Full mode encodes every character, producing output safe for transit through systems that mangle encoding (legacy email gateways, certain CMS platforms, database fields with charset mismatches). Note: this tool operates on code points 0 - 255 (ISO 8859-1 / Latin-1 superset). Characters beyond U+00FF are encoded as decimal or hex numeric references but fall outside the classical ASCII/Extended ASCII range.
Formulas
The conversion algorithm iterates over each character in the input string. For each character at index i, the code point c is extracted.
The encoder then applies one of three output formats based on user selection:
In selective mode, only characters satisfying the predicate are encoded:
In full mode, every character (except whitespace control characters like newline and tab, which are preserved for readability) is encoded:
Where c = Unicode code point of the character. The hexadecimal conversion uses uppercase letters and the toString(16) base conversion. Named entity lookup is performed via a hash map with O(1) average access time, covering 97 standard HTML5 named references.
Reference Data
| Character | Description | ASCII Code | Named Entity | Decimal | Hex |
|---|---|---|---|---|---|
| & | Ampersand | 38 | & | & | & |
| < | Less-than sign | 60 | < | < | < |
| > | Greater-than sign | 62 | > | > | > |
| " | Double quote | 34 | " | " | " |
| ' | Apostrophe | 39 | ' | ' | ' |
| Non-breaking space | 160 | ||||
| © | Copyright | 169 | © | © | © |
| ® | Registered | 174 | ® | ® | ® |
| ™ | Trademark | 8482 | ™ | ™ | ™ |
| € | Euro sign | 8364 | € | € | € |
| £ | Pound sign | 163 | £ | £ | £ |
| ¥ | Yen sign | 165 | ¥ | ¥ | ¥ |
| ¢ | Cent sign | 162 | ¢ | ¢ | ¢ |
| § | Section sign | 167 | § | § | § |
| ¶ | Pilcrow (paragraph) | 182 | ¶ | ¶ | ¶ |
| ° | Degree sign | 176 | ° | ° | ° |
| ± | Plus-minus | 177 | ± | ± | ± |
| µ | Micro sign | 181 | µ | µ | µ |
| · | Middle dot | 183 | · | · | · |
| × | Multiplication | 215 | × | × | × |
| ÷ | Division | 247 | ÷ | ÷ | ÷ |
| ½ | One half | 189 | ½ | ½ | ½ |
| ¼ | One quarter | 188 | ¼ | ¼ | ¼ |
| ¾ | Three quarters | 190 | ¾ | ¾ | ¾ |
| « | Left guillemet | 171 | « | « | « |
| » | Right guillemet | 187 | » | » | » |
| ¿ | Inverted question mark | 191 | ¿ | ¿ | ¿ |
| ¡ | Inverted exclamation | 161 | ¡ | ¡ | ¡ |
| - | Em dash | 8212 | — | — | — |
| - | En dash | 8211 | – | – | – |