# Unescape HTML special characters

Turn &amp; &lt; &gt; &quot; and &#39; back into characters in one pass.

Canonical: https://1loc.dev/string/unescape-html-special-characters/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function unescapeHtml(text) { return text.replace(/&(?:amp|lt|gt|quot|#0*39);/g, entity => ({ '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '"' })[entity] ?? "'"); }
```

## Input

```json
"&lt;b&gt;Ana &amp; Rui&lt;/b&gt;"
```

## Expected output

```json
"<b>Ana & Rui</b>"
```

## Edge case

Input:
```json
"&amp;lt;"
```
Output:
```json
"&lt;"
```

## Limits

- The original replaced entities one after another, so "&amp;lt;" became "<". A single pass keeps it as "&lt;".

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/unescape-html-special-characters.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Single pass, so already-escaped entities are not unescaped twice as in the original sequence of replacements. Original MDX retained as inert source evidence.
