# HTML Entities Encoder/Decoder API

> HTML Entities Encoder/Decoder converts special characters into safe HTML entities or restores encoded strings back to standard text. Pass any HTML markup or text snippet to receive the converted string, a replacement count, and a list of modified characters.

**Endpoint:** `POST https://api.apiverve.com/v1/htmlentities`  
**Category:** Data Conversion  
**Cost:** 1 credit per call  
**Canonical page:** https://apiverve.com/marketplace/htmlentities

## Overview

An HTML entities encoder and decoder for making text safe to drop into a page, or for reading encoded markup back as plain characters. Set action to encode for HTML encode (escape) or decode for HTML decode (unescape), POST the string, and get back the converted text with a count of replacements and a list of which characters or entities were involved.

Escaping the characters that carry meaning in HTML is a basic step in XSS prevention when user input ends up in templates, emails or admin screens. The decode direction helps when scraped content, RSS feeds or database exports arrive full of &lt; and &quot; sequences that need to be shown or searched as normal text.

There is no plan difference here: the Free plan and paid plans run the same conversion and return the same fields.

## Authentication

Every call carries your key in an `x-api-key` header. The same key works across the whole
APIVerve catalog — there are no per-API subscriptions. Responses always use the same three
top-level keys: `status`, `error`, and `data`.

## Example request

```bash
curl -X POST "https://api.apiverve.com/v1/htmlentities" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html":"<div class=\"test\">Hello & World</div>","action":"encode"}'
```

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `html` | string | Yes | The HTML content to encode |
| `action` | string | No | The action to perform. default encode. One of: encode, decode |

## Response fields

- `action` — string · The action performed on the HTML content
- `original` — string · The original HTML content before encoding
- `encoded` — string · The HTML content with entities encoded
- `entities_replaced` — array · Array of special characters that were replaced
- `count` — number · Total number of entity replacements made

## Sample response

```json
{
  "status": "ok",
  "error": null,
  "data": {
    "action": "encode",
    "original": "<div class=\"test\">Hello & World</div>",
    "encoded": "&lt;div class=&quot;test&quot;&gt;Hello &amp; World&lt;&#x2F;div&gt;",
    "entities_replaced": [
      "<",
      "\"",
      ">",
      "&",
      "/"
    ],
    "count": 8
  }
}
```

## Use cases

- **XSS Prevention** — Encode user input before displaying in HTML to prevent cross-site scripting (XSS) attacks
- **Data Display** — Decode HTML entities in stored content to display special characters correctly in web applications
- **Content Migration** — Encode or decode HTML entities when migrating content between systems with different encoding requirements
- **API Integration** — Properly encode HTML content before sending to APIs or decode entities received from external sources

## SDKs

- **npm** — `npm install @apiverve/htmlentities` (https://www.npmjs.com/package/@apiverve/htmlentities)
- **NuGet** — `dotnet add package APIVerve.API.HTMLEntitiesEncoderDecoder` (https://www.nuget.org/packages/APIVerve.API.HTMLEntitiesEncoderDecoder)
- **Source** — https://github.com/apiverve/htmlentities-api

## More

- Full reference: https://docs.apiverve.com/ref/htmlentities
- Get an API key: https://dashboard.apiverve.com
- Full catalog: https://apiverve.com/marketplace
