HTML Sanitizer API

Strip scripts, iframes, forms, event handlers, inline styles and javascript: links from untrusted HTML before you display it.

POSThttps://apibox.io.vn/v1/html-sanitize
Content & HTML▶ Try it online

Send untrusted HTML in the html field (JSON or form) or as a raw text/html body and get a cleaned version back in html. The sanitizer parses the markup and removes dangerous elements entirely: script, style, iframe, object, embed, form, input, button, link, meta, base, frame and frameset.

On the remaining elements it removes every on* event handler (onclick, onerror...), every style attribute, and href, src, xlink:href or action values that start with javascript:, vbscript: or data:text. Regular formatting, links, images and tables are kept. This is the same sanitizer used by the Markdown to HTML endpoint.

The request body is limited to 1 MB and html to 2,000,000 characters. The sanitizer works on a block list, so for highly sensitive contexts combine it with a Content Security Policy.

Parameters

NameInTypeRequiredDefault
htmlbodystringyesHTML to sanitize (max 2,000,000 characters). Can also be sent as a raw text/html body.

Example

curl -X POST "https://apibox.io.vn/v1/html-sanitize" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html":"<p onclick=\"alert(1)\" style=\"color:red\">Hi <a href=\"javascript:alert(1)\">click</a></p><script>alert(2)</script><img src=\"x\" onerror=\"alert(3)\">"}'

Response

{
  "html": "<p>Hi <a>click</a></p><img src=\"x\">"
}

Use cases

  • Clean user-generated HTML from comments, forums or rich-text editors
  • Remove tracking scripts and inline styles from imported content
  • Sanitize HTML emails before showing them in a web app
  • Prepare scraped HTML for safe storage and rendering

FAQ

Which tags and attributes are removed?

script, style, iframe, object, embed, form, input, button, link, meta, base, frame and frameset elements, all on* event handlers, all style attributes, and javascript:, vbscript: or data:text URLs in href, src, xlink:href and action.

Are links and images kept?

Yes. Normal <a href> and <img src> are kept; only dangerous URL schemes and event handlers such as onerror are removed.

Can I send raw HTML without JSON?

Yes. POST the HTML as the request body with Content-Type: text/html.

Related APIs

Start with 1,000 free requests every month. Get free API key →