# Bun Escape an HTML string

> Escape an HTML string

- Skill: `jarle/bun-escape-an-html-string` (Agent Skill)
- Install (CLI): `npx skillmds@latest add jarle/bun-escape-an-html-string`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jarle/bun-escape-an-html-string/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: jarle (https://skillmd.com/u/jarle)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/jarle/bun-escape-an-html-string

---


# Escape an HTML string

The `Bun.escapeHTML()` utility can be used to escape HTML characters in a string. The following replacements are made.

* `"` becomes `"&quot;"`
* `&` becomes `"&amp;"`
* `'` becomes `"&#x27;"`
* `<` becomes `"&lt;"`
* `>` becomes `"&gt;"`

This function is optimized for large input. Non-string types will be converted to a string before escaping.

```ts  theme={"theme":{"light":"github-light","dark":"dracula"}}
Bun.escapeHTML("<script>alert('Hello World!')</script>");
// &lt;script&gt;alert(&#x27;Hello World!&#x27;)&lt;&#x2F;script&gt;
```

***

See [Docs > API > Utils](/runtime/utils) for more useful utilities.

