HTML Entity Encoder / Decoder

HTML Entity Encoder / Decoder API

Development

Escape text for HTML or decode named, decimal and hex entities as you type, with options for just the unsafe characters or all non-ASCII, and a searchable entity table.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

120 requests per minute

Endpoints

1 endpoint available

Overview

Encode text as HTML entities, decode entities back to plain text, or search the table of named entities.

Operations

  • encode: escape text for HTML. scope "unsafe" (default) escapes only & < > " and '. "non-ascii" also escapes every character above ASCII. style is "named" (default, like &eacute;), "decimal" (&#233;) or "hex" (&#xE9;). In named style, characters with no name in the table use a decimal reference, and the apostrophe is always &#39;.
  • decode: turn entities back into characters. Decimal and hex references work for any character. Named entities work for the names in the entity table, which covers the HTML 4 set plus &apos;. Other names, and names without the closing semicolon, are left as written. The web page decodes with the browser's parser, which knows every HTML5 name, so it recognises more names than the API does.
  • lookup: search the entity table. query matches a name (with or without the & and ;), part of a description, the character itself, or its decimal or hex code point. group limits results to one group.

Notes

  • text is limited to 100,000 characters.
  • Encoding is for HTML text and attribute values. It does not make text safe inside script or style blocks, or in URLs.
  • references in an encode response counts the entities in the output.
  • Groups: Reserved, Spaces and invisible, Punctuation, Currency, Symbols, Maths, Arrows, Greek, Latin letters.

Endpoints

POST
https://opentools.ca/api/v1/tools/html-entity-encoder
Encode text to HTML entities, decode entities, or look up entities

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
operation
string
Enum: encode, decode, lookup
Required
The operation to perform
text
string
OptionalText to encode or decode, 1-100,000 characters. Required for "encode" and "decode".
scope
string
Enum: unsafe, non-ascii
OptionalWhat to escape when encodingDefault: unsafe
style
string
Enum: named, decimal, hex
OptionalEntity style when encodingDefault: named
query
string
OptionalSearch term for "lookup", up to 100 characters. Empty matches every entity.
group
string
OptionalLimit "lookup" to one group, for example "Currency" or "Arrows"
limit
number
OptionalMaximum entities returned by "lookup", 1-300Default: 50

Response Example

{
  "success": true,
  "operation": "encode",
  "scope": "non-ascii",
  "style": "named",
  "output": "caf&eacute; &lt;b&gt;5 &euro;&lt;/b&gt;",
  "references": 6
}

Error Codes

400
Bad Request - Missing or oversized input, or an invalid operation, scope, style or group
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key is inactive or expired, or the request IP is not allowed
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code Examples

# Encode
curl -X POST https://opentools.ca/api/v1/tools/html-entity-encoder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"operation": "encode", "text": "café <b>5 €</b>", "scope": "non-ascii"}'

# Decode
curl -X POST https://opentools.ca/api/v1/tools/html-entity-encoder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"operation": "decode", "text": "caf&eacute; &lt;b&gt;"}'

# Look up an entity
curl -X POST https://opentools.ca/api/v1/tools/html-entity-encoder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"operation": "lookup", "query": "euro"}'

Ready to get started?

Create an API key to start using the HTML Entity Encoder / Decoder API.

Rather use it in your browser? Open the HTML Entity Encoder / Decoder