HTML Entities Encoder/Decoder
Free HTML Entities Encoder and Decoder — convert special characters to safe HTML entities and back. Prevent XSS attacks, fix broken characters in web pages, and ensure proper display of special symbols. Includes complete HTML entity reference table.
Overview
HTML entities are a fundamental aspect of web development, providing a mechanism to display characters that have special significance in HTML or are not readily available on a standard keyboard. These entities are placeholders, or character references, that a browser interprets and renders as the intended character. For instance, the less-than symbol (<) is a reserved character used to start an HTML tag. To display it as text, one must use its corresponding entity, either the named entity `<` or the numeric entity `<`. This system ensures that the browser\'s parser doesn\'t confuse content with markup, preventing rendering errors and maintaining the structural integrity of the document. Understanding and utilizing HTML entities is crucial for any developer aiming to create robust and error-free web pages, especially when dealing with dynamic content or user-generated input where the presence of special characters is unpredictable.
The technical implementation of HTML entities is rooted in character encoding standards like ASCII and Unicode. Each character is mapped to a unique numeric code point. HTML entities can reference these characters either by a descriptive name (e.g., `©` for the copyright symbol) or by their numeric code point in decimal (`©`) or hexadecimal (`©`) format. While named entities are more memorable and improve code readability, numeric entities offer broader compatibility, especially for less common characters or symbols that may not have a designated name. The choice between named and numeric entities often depends on the specific use case, with developers balancing readability against the need for comprehensive character support. Modern web development heavily relies on UTF-8, a variable-width character encoding that can represent every character in the Unicode standard, making the use of entities for special characters seamless and consistent across different platforms and browsers.
The importance of HTML entities extends beyond simply displaying special characters. They play a vital role in web security, particularly in preventing Cross-Site Scripting (XSS) attacks. When a website displays user-provided input without proper sanitization, malicious actors can inject scripts containing HTML tags. By converting special characters like `<` and `>` into their corresponding entities, developers can neutralize these scripts, ensuring they are rendered as harmless text rather than being executed by the browser. Furthermore, using entities for special characters ensures cross-platform and cross-browser compatibility, as it guarantees that symbols will be displayed correctly regardless of the user\'s operating system or browser, which might otherwise misinterpret or fail to render certain characters. Therefore, a solid grasp of HTML entities is not just about proper rendering but is a cornerstone of secure and universally accessible web development.
Worked example
A product title with an ampersand and quotes going into an attribute
A shop owner has the product title Bob's "Classic" T-Shirt & Mug — 12 oz and needs it inside the title attribute of a link without breaking the attribute, without breaking the text, and with a clear idea of what the numeric alternative looks like.
- Open the Encode tab, leave Entity Type on Named, and leave the spaces checkbox off so that spaces stay spaces and the title stays readable in the source.
- Paste the 37-character title. The output box fills as you type and reads Bob's "Classic" T-Shirt & Mug — 12 oz.
- Four characters were replaced: the apostrophe became ', each double quote became ", the ampersand became & and the em dash became —. The letters, the digits, the hyphens and every space were left alone.
- Paste that into the attribute: title="Bob's "Classic" T-Shirt & Mug — 12 oz". The quotes inside the value are entities now, so the title cannot terminate the attribute early, which is the bug this pass exists to prevent.
- Switch Entity Type to Numeric to see the other option: the same title becomes 37 decimal references, from B for the B to z for the z, 201 characters in total. Every character including each space is replaced, so nothing is left literal.
- Press Copy and use the result where it is needed. The Rendered HTML Preview panel shows what a browser makes of the text, inside a sandboxed frame where scripts, forms, popups and same-origin access are all disabled.
- To go back the other way, switch to Decode and paste &lt;p&gt;Hello&lt;/p&gt;. The tool warns that the input looks double-encoded, because one pass returns <p>Hello</p> and the markup appears only after a second pass.
Result: The title goes into the attribute as Bob's "Classic" T-Shirt & Mug — 12 oz, with the quote and the ampersand escaped while the spaces stay spaces. When named entities are not an option, the numeric mode produces the same title as 37 references and 201 characters.
How to use HTML Entities Encoder/Decoder
- Enter text
- Click Encode or Decode
- View entities
- Copy to clipboard
Common mistakes
Running a full URL through the HTML entity encoder to make it safe.
The encoder covers markup characters and a list of typographic ones; it does not touch spaces, question marks, equals signs, hashes or non-ASCII letters, although the ampersand does become &. A URL with a space in it is still broken, and anything that reads the value outside an HTML parser, such as a spreadsheet, a redirect header or a plain-text mail, receives the literal characters & and ". Use url-encoder for the URL and this tool only for the HTML that wraps it.
Assuming that named encoding escapes everything that could be dangerous.
Named mode knows a fixed table of 35 characters, so accented letters, emoji, currency signs outside the table and every other code point are passed through unchanged. For text that must survive a pipeline which mangles bytes, or for a document in a language without named entities, switch to Numeric, which replaces every character with its decimal code point.
Decoding untrusted markup and then rendering it in a page.
Decoding is a text transformation, not a sanitiser: a payload comes back as live markup, and inserting that into a document is an injection. The preview here is confined to a sandboxed frame for exactly that reason. Treat the decoded output as data and escape it again at the point where it enters a page.
Wondering why one decode pass leaves entities behind in the text.
Double-encoded input such as &amp; needs two passes, and the tool shows a warning when it sees the pattern. Decode until the text stops changing, but remember that each pass converts more of the original markup into live characters, which is the opposite of what a safety check wants.
Features
- Encode/decode
- Named/numeric entities
- XSS prevention
- Copy to clipboard
Limits worth knowing
- Named encoding covers a fixed table of 35 characters: the five markup characters ampersand, less than, greater than, double quote and apostrophe, the non-breaking space, and 29 typographic, currency and symbol characters. Everything else is passed through untouched.
- Encoding offers named and decimal numeric references only. Hex references such as ' are understood when decoding but are never produced, and there is no way to escape only selected characters or to exclude one that should stay literal.
- Decoding runs through the browser HTML parser in a detached textarea, so it resolves the named references that browser knows plus decimal and hex references. A reference the browser does not know, or a malformed one, is left exactly as written and counted in the could not be decoded message.
- The apostrophe is emitted as ', which is defined in XML and in HTML5 but not in HTML 4.01, so a document with an HTML4 doctype is better served by the numeric form '. Spaces become only when the checkbox is on, and that checkbox exists only in named mode, where numeric mode encodes every space anyway.
- Text in and text out only: no file upload, no batch mode, no download, no history and no stated input size limit. The copy button uses the clipboard API, which needs a secure context and a click, and the sandboxed preview shows static markup rather than a working page.
When to use it
- A developer writing a tutorial needs to show HTML code examples on a webpage. They use an HTML entities tool to convert all the `<` and `>` characters in their code snippets to `<` and `>` so the browser displays the code as text instead of rendering it as HTML.
- A math blogger is writing an article that includes complex formulas and equations. They use an HTML entities tool to find and insert the correct entities for mathematical symbols like `∑` (summation), `∫` (integral), and `√` (square root).
- A technical writer is creating online help documentation for a software product. They use an HTML entities tool to insert special characters like the copyright (`©`) and registered trademark (`®`) symbols, ensuring legal compliance and a professional appearance.
- An e-commerce manager is adding product descriptions that include measurements and currency symbols. They use an HTML entities tool to ensure that symbols like the degree sign (`°`) and the Euro symbol (`€`) are displayed correctly for all users.
- A social media manager wants to use special symbols and emojis in a post to make it more engaging. They use an HTML entities tool to find the right entities for characters that might not be easily accessible on their keyboard, ensuring the post looks the same on all devices.
- A frontend developer is building a comment section for a blog. They use an HTML entities tool to sanitize user-submitted comments, converting any HTML tags into entities to prevent XSS attacks and ensure the security of the website.
Practical tips
- Favor Named Entities for Clarity: Whenever possible, use named entities (e.g., `—` for an em dash) over their numeric counterparts. They are more descriptive and make your HTML source code significantly more readable and easier to maintain for other developers.
- Use Numeric Entities for Obscure Characters: For symbols that do not have a named entity, or for characters outside the standard Latin-1 character set, use numeric entities. This ensures the broadest possible browser compatibility and is essential for multilingual websites.
- Master the Non-Breaking Space: The ` ` entity is a powerful tool for controlling layout. Use it to prevent line breaks between words that should always stay together, such as a number and its unit (e.g., `10 km`).
- Be Mindful of Character Encoding: Always declare your character encoding (preferably UTF-8) in the `<head>` of your HTML document. This ensures that the browser correctly interprets your HTML entities and displays all characters as intended, avoiding garbled text.
- Don\'t Overuse Entities: While essential for special characters, avoid using entities for standard alphanumeric characters. Overusing them can make your HTML harder to read and slightly increase file size. Reserve them for characters that have special meaning in HTML or are not on your keyboard.
Why use this tool
- Prevent Rendering Errors: Avoid unexpected layout breaks and rendering issues by encoding reserved HTML characters like `<`, `>`, and `&`. This ensures that your content is displayed exactly as you intend, without being misinterpreted as HTML code by the browser.
- Enhance Web Security: Protect your website from Cross-Site Scripting (XSS) vulnerabilities. By converting user-supplied input into HTML entities, you can neutralize malicious scripts and prevent them from being executed, safeguarding your users and your application.
- Ensure Cross-Browser Compatibility: Guarantee that special characters and symbols are displayed consistently across all web browsers and operating systems. This eliminates the risk of characters appearing as broken or incorrect symbols for some users, providing a uniform experience for everyone.
- Improve Code Readability: Make your HTML code cleaner and more understandable by using named entities like `©` or `®`. This practice makes the code easier to read, maintain, and debug for you and your team.
- Display a Wide Range of Symbols: Easily insert a vast array of special characters, including mathematical symbols, currency signs, and emojis, that are not available on a standard keyboard. This allows you to create richer and more expressive content.
- Maintain Content Integrity: Preserve the formatting and spacing of your text. Use entities like the non-breaking space (` `) to control word wrapping and ensure that related elements, such as units and values, stay together on the same line.
When this is not the right tool
- The string is destined for a URL or a query parameter. — url-encoder, which percent-encodes spaces, question marks, equals signs, hashes and non-ASCII characters, none of which entity encoding addresses.
- The text has to be safe inside a JavaScript string, a JSON document or a CSV file. — json-formatter for JSON, because HTML entities mean nothing to a JSON parser and & would arrive as those four literal characters.
- The real goal is to stop a stored value from becoming executable markup. — escaping at the point of output on the server or in the template engine, because encoding a value in a browser tab changes nothing about the data that was already stored.
Frequently asked questions
HTML entities?
Special codes for characters: & for &, < for <.
Why use?
Correct display and XSS security prevention.
Named vs numeric?
Named (&) readable. Numeric (&) for any Unicode.
Common ones?
< > & " '
Related tools in Developer Tools
- JSON Formatter — Free JSON Formatter and Validator — beautify, minify, validate, and debug JSON data instantly.
- Base64 Encoder/Decoder — Free Base64 Encoder and Decoder — convert text, files, and images to Base64 encoding and back.
- URL Encoder/Decoder — URL Encoder/Decoder converts special characters to percent-encoded equivalents.
- Regex Tester — The Regex Tester lets you write, test, and debug regular expressions in real-time with match highlighting and capture group display.
- Timestamp Converter — The Timestamp Converter converts between Unix timestamps and human-readable dates.
- Color Contrast Checker — Free color contrast checker for web accessibility.
- File Encryptor — Encrypt a file with AES-256-GCM, using a key derived from your password with PBKDF2-SHA256.
Further reading
HTML Entity Encoder/Decoder: Convert Special Characters
Encode special characters to HTML entities or decode entities back to characters. Prevent XSS and display special characters correctly.