← Back to FreeTextUtils  · 

📅 Updated: June 1, 2026 | ⏱️ Reading time: 10 minutes | ✍️ By FreeTextUtils Team

What Are HTML Entities?

HTML entities are special codes used to represent characters that have special meaning in HTML or characters that cannot be typed directly on a keyboard. An HTML entity begins with an ampersand (&) and ends with a semicolon (;). There are two types: named entities (like < for less-than) and numeric entities (like < for the same character).

HTML entities serve two primary purposes: they allow you to display characters that would otherwise be interpreted as HTML code (like angle brackets), and they enable you to include characters from various character sets using ASCII-safe text. Without HTML entities, it would be impossible to display an actual less-than sign (<) on a web page without the browser interpreting it as the start of an HTML tag.

Understanding HTML entities is fundamental for web developers, content authors, and anyone who works with HTML-based content. In an era where web security is paramount, proper entity encoding is also a critical defense against cross-site scripting (XSS) attacks.

Common HTML Entities Reference

Here are the most frequently used HTML entities that every web developer should know:

Character Description Named Entity Numeric Entity
<Less than&lt;&#60;
>Greater than&gt;&#62;
&Ampersand&amp;&#38;
"Double quote&quot;&#34;
'Single quote (apostrophe)&apos;&#39;
 Non-breaking space&nbsp;&#160;
©Copyright&copy;&#169;
®Registered trademark&reg;&#174;
Trademark&trade;&#8482;
Euro currency&euro;&#8364;
£Pound currency&pound;&#163;
¥Yen currency&yen;&#165;
Em dash&mdash;&#8212;
Horizontal ellipsis&hellip;&#8230;

In addition to these common entities, there are hundreds of named entities for accented characters, mathematical symbols, Greek letters, arrows, and other special characters. The HTML5 specification defines over 2,000 named character entities.

Encoding Text to HTML Entities

Encoding converts regular text characters into their corresponding HTML entities. This is essential when you want to display text that contains characters with special meaning in HTML. The process is straightforward:

  1. Identify characters that need encoding: <, >, &, ", '
  2. Replace each character with its corresponding named or numeric entity
  3. Optionally encode additional characters (non-ASCII, symbols) for full entity representation

Example: Encoding a Code Snippet

Original text:

Encoded as HTML entities:

Use the &lt;a&gt; tag for links and set href=&quot;https://example.com&quot;

When rendered in a browser, the encoded version displays the actual source code characters, including angle brackets and quotes, without being interpreted as HTML.

Decoding HTML Entities

Decoding is the reverse operation: converting HTML entities back into their actual characters. This is commonly needed when processing HTML content from external sources, parsing RSS feeds, working with API responses that deliver HTML-encoded text, or cleaning up formatted text for display in plain-text contexts.

Decoding handles both named entities (&lt;) and numeric entities (&#60;). Most modern programming languages have built-in functions for this, but our online tool provides a quick, browser-based solution without requiring any code.

When to Decode

  • Extracting text from HTML content for search indexing
  • Displaying HTML-encoded API responses in plain text
  • Cleaning up user-generated content that has been double-encoded
  • Migrating content between systems that use different encoding schemes
  • Preparing text for export to non-HTML formats (PDF, DOCX, plain text files)

Why HTML Entities Matter in Web Development

Security: Preventing XSS Attacks

Cross-site scripting (XSS) is one of the most common web security vulnerabilities. Attackers inject malicious scripts into web pages by embedding JavaScript code in user input fields, URL parameters, or database entries. Proper HTML entity encoding neutralizes these attacks by ensuring that injected code is displayed as harmless text rather than executed by the browser. Always encode user-generated content before displaying it on your web pages.

Content Accuracy

Many characters — especially currency symbols, mathematical operators, and punctuation — have special meanings in HTML or may not be supported by all character encodings. Using HTML entities ensures that these characters display correctly across all browsers and operating systems.

SEO and Accessibility

Search engines and assistive technologies (like screen readers) need to interpret your content accurately. Proper use of HTML entities ensures that special characters are understood correctly. For example, using &copy; for the copyright symbol ensures that screen readers pronounce it correctly.

Internationalization

HTML entities provide a way to include characters from any language or script without relying on the document's character encoding. This is particularly useful when you need to include a few characters from a different script without switching the entire page encoding.

Real-World Examples

Example 1: Displaying Code in a Blog Post

Scenario: A technical blogger wants to write a tutorial about HTML forms that includes sample code with angle brackets.

Challenge: Without encoding, the browser interprets <input type="text"> as actual HTML and renders a form field instead of showing the code.

Solution: The blogger encodes the code snippets using the HTML entities converter. Each < becomes &lt; and each > becomes &gt;. The encoded code displays correctly in the tutorial, ready for readers to copy and use.

Example 2: Processing User Comments

Scenario: A news website allows readers to post comments. A user submits a comment containing <script>alert('XSS')</script>.

Challenge: If stored and displayed without encoding, this script would execute in other users' browsers, creating an XSS vulnerability.

Solution: The application runs all user comments through the HTML entities encoder before storing them. The malicious script is converted to harmless text: &lt;script&gt;alert('XSS')&lt;/script&gt;. The comment is displayed safely without executing.

Example 3: Importing Content from a CMS

Scenario: A content team migrates articles from an old CMS to a new one. The old CMS encoded all special characters.

Challenge: The articles contain &mdash;, &hellip;, and &nbsp; entities that need to be decoded for the new system.

Solution: The team pastes each article into the HTML entities decoder, which converts all entities back to actual characters. The clean text is then imported into the new CMS, where it gets re-encoded according to the new system's standards.

Frequently Asked Questions

Q: What is the difference between named and numeric entities?

A: Named entities use descriptive names like &lt; and are easier to remember. Numeric entities use Unicode code points like &#60; and can represent any character, even those without a named entity. Both render identically in browsers.

Q: Do I need to encode every special character?

A: No. Only characters that have special meaning in HTML (<, >, &, ") must be encoded for content that is not inside HTML tags. Characters like and © are optional but improve compatibility.

Q: Does URL encoding work the same as HTML entity encoding?

A: No. URL encoding (percent encoding) uses % followed by hex codes for URLs. HTML entity encoding uses & followed by names or numbers for HTML content. They serve different purposes and are not interchangeable.

Q: Can I use HTML entities in other markup languages?

A> HTML entities work in HTML and XML documents. Markdown supports some HTML entities, but not all renderers handle them consistently. JSON and other data formats do not use HTML entities.

Q: What happens if I forget the semicolon?

A: Most modern browsers are lenient and will still render the entity correctly in many cases. However, the HTML specification requires the semicolon, and omitting it may cause rendering issues in some contexts. Always include the semicolon.

Ready to Encode or Decode HTML Entities?

Use our free online HTML entities converter to transform special characters instantly:

  • Encode text to HTML entities
  • Decode HTML entities back to text
  • Supports all named and numeric entities
  • 100% browser-based processing
  • Copy results with one click
Go to HTML Entities Converter Tool