# HTML entity encoder and decoder

Escape text as HTML entities, named or numeric, or decode entities back to characters.

- Endpoint: `POST https://setget.net/v1/tools/html-entities` with JSON `{"input": {...}}`
- MCP: `run_tool` with `slug` = `html-entities`
- Page: https://setget.net/tools/html-entities

## Inputs

- `text` (required, string): The text to escape, or text with entities to decode.
- `action` (optional, string, one of `encode`, `decode`, default `"encode"`): Encode characters as entities, or decode entities to characters.
- `style` (optional, string, one of `named`, `decimal`, `hex`, default `"named"`): How to write entities: named where a name exists (&eacute;), decimal (&#233;) or hex (&#xE9;).
- `scope` (optional, string, one of `all`, `special`, `non-ascii`, default `"all"`): What to encode: "special" is only & < > " and ', "non-ascii" is only characters outside plain ASCII, "all" is both.

## Example 1

```json
{"input":{"text":"<p>Café & \"tea\"</p>"}}
```

Result:

```json
{"text":"&lt;p&gt;Caf&eacute; &amp; &quot;tea&quot;&lt;/p&gt;","replaced":8}
```

## Example 2: Only non-ASCII characters, leaving the markup alone

```json
{"input":{"text":"Café <b>€5</b>","style":"decimal","scope":"non-ascii"}}
```

Result:

```json
{"text":"Caf&#233; <b>&#8364;5</b>","replaced":2}
```

## Example 3

```json
{"input":{"text":"&lt;p&gt;Caf&eacute; &amp; &#8364;5 &#x1F600;&lt;/p&gt;","action":"decode"}}
```

Result:

```json
{"text":"<p>Café & €5 😀</p>"}
```

**Which characters must be escaped in HTML?** Always & and <. Inside attribute values also the quote character. Escaping > and both quotes everywhere, as "special" does, is the safe habit.

**Is escaping enough to stop XSS?** Only when the text is placed in HTML content or a quoted attribute. Text placed inside a script, a style or a URL needs different escaping.

**Why is the apostrophe written as &#39;?** It works everywhere, while the named form &apos; is not understood by some older HTML readers.
