# html-entity-codec

> Decode, encode, and escape HTML character references

Latest version **1.1.0** (published 2026-09-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install html-entity-codec
pnpm add html-entity-codec
yarn add html-entity-codec
bun add html-entity-codec
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2026-09-06 |
| First published | 2026-09-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18.20.8 |
| Dependencies | 0 |
| Unpacked size | 117.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 214 |
| Author | Roy Revelt |
| Maintainers | royston |
| Keywords | decode, encode, entities, escape, html |

## Links

- npm: https://www.npmjs.com/package/html-entity-codec
- Repository: https://github.com/codsen/codsen
- Homepage: https://codsen.com/os/html-entity-codec
- Issues: https://github.com/codsen/codsen/issues
- npm.io page: https://npm.io/package/html-entity-codec

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2026-09-06
- 0.0.1 — 2026-09-05

## README

<h1 align="center">html-entity-codec</h1>

<p align="center">Decode, encode, and escape HTML character references</p>

<p align="center">
  <a href="https://codsen.com/os/html-entity-codec" rel="nofollow noreferrer noopener">
    <img src="https://img.shields.io/badge/-codsen-blue?style=flat-square" alt="page on codsen.com">
  </a>
  <a href="https://www.npmjs.com/package/html-entity-codec" rel="nofollow noreferrer noopener">
    <img src="https://img.shields.io/badge/-npm-blue?style=flat-square" alt="page on npm">
  </a>
  <a href="https://github.com/codsen/codsen/tree/main/packages/html-entity-codec" rel="nofollow noreferrer noopener">
    <img src="https://img.shields.io/badge/-github-blue?style=flat-square" alt="page on github">
  </a>
  <a href="https://npmcharts.com/compare/html-entity-codec?interval=30" rel="nofollow noreferrer noopener" target="_blank">
    <img src="https://img.shields.io/npm/dm/html-entity-codec.svg?style=flat-square" alt="Downloads per month">
  </a>
  <a href="https://codsen.com/os/html-entity-codec/changelog" rel="nofollow noreferrer noopener">
    <img src="https://img.shields.io/badge/changelog-here-brightgreen?style=flat-square" alt="changelog">
  </a>
  <img src="https://img.shields.io/badge/licence-MIT-brightgreen.svg?style=flat-square" alt="MIT Licence">
</p>

**No dependencies whatsoever.** This package declares no dependencies or devDependencies.

## Features

HTML character-reference transformations from pinned WHATWG data.

- Decode in one pass with text or attribute context and explicit semicolon and parse-error policies.
- Encode with stable named aliases or uppercase hexadecimal references; the dedicated numeric encoder lets bundlers omit named data.
- Escape quoted attributes and ordinary HTML text, with optional progress and completion callbacks.
- Keep source offsets through the reference scanner.

## Install

This package is [pure ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).

```bash
npm i html-entity-codec
```

## Quick Take

```js
import assert from "node:assert/strict";
import { decode } from "html-entity-codec";

assert.equal(
  decode("Cat &amp; fiddle &#128572;&#127931;"),
  "Cat & fiddle 😼🎻",
);
```


## Documentation

Please [visit codsen.com](https://codsen.com/os/html-entity-codec/) for a full description of the API. For **Changelog**, see [raw md on GitHub](https://github.com/codsen/codsen/blob/main/packages/html-entity-codec/CHANGELOG.md) or [the website](https://codsen.com/os/html-entity-codec/changelog).

## Contributing

To report bugs or request features or assistance, [raise an issue](https://github.com/codsen/codsen/issues/new/choose) on GitHub.

## Licence

MIT License

Copyright © 2010-2026 Roy Revelt and other contributors

HTML [named character references](https://html.spec.whatwg.org/entities.json) - Copyright © WHATWG (Apple, Google, Mozilla, Microsoft) - see its [BSD-3-Clause disclaimer](https://opensource.org/licenses/BSD-3-Clause)

<p align="center"><img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center"></p>

---
_Source: https://npm.io/package/html-entity-codec · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
