Free plan

Clean HTML

Tidy messy web code and remove unsafe parts
POST
/v1/documents/clean-html

About this tool

This tool cleans HTML, which is the code behind a web page. It removes scripts and other unsafe or unwanted parts, strips styles and empty pieces, and keeps a safe set of tags. It can also give you only the main article, plain text or Markdown (text with simple marks). It tells you how much it removed.
For example, you paste text copied from Word and clean it before putting it on your website.

How to use it

  1. Choose this tool.
  2. Add your HTML file, or paste the code into the box.
  3. Choose the form you want: tidy HTML, main article only, plain text or Markdown.
  4. Choose what to do with links, pictures and styles, if you like.
  5. Press Generate, then copy or download the result.

What you get back

You get the cleaned result, which you can copy or download, along with counts of what was removed.
GOOD TO KNOW
The HTML is parsed, never run, and nothing is fetched. mode=article needs real article text (400 when none is found). Counts as one document.
TEST IT LIVE

Try Clean HTML in the Studio

One click opens the Studio with this tool already selected. Add your file and see the result in seconds.
Open in the Studio
Family
Documents
Plan
Free
Method
POST
Endpoint
/v1/documents/clean-html
Tool ID
documents.clean-html
Authentication
API key
Accepts
Text and settings
Background jobs
Yes
Usage group
Documents
For developers

Use it from your code

cURL

curl -X POST "https://app.h2i.davixlabs.io/v1/documents/clean-html" \
  -H "X-Api-Key: $DAVIX_H2I_API_KEY" \
  -F 'html=<div onclick="x()"><h1>Title</h1><script>alert(1)</script></div>' \
  -F 'mode=sanitize' \
  -F 'allow_tags=["p","a","strong"]'

Node.js

const { DavixH2I } = require('@davixlabs/h2i-sdk');

const h2i = new DavixH2I({ apiKey: process.env.DAVIX_H2I_API_KEY, baseUrl: process.env.DAVIX_H2I_URL });
const result = await h2i.documents.cleanHtml({
    "html": "<div onclick=\"x()\"><h1>Title</h1><script>alert(1)</script></div>",
    "mode": "sanitize",
    "allow_tags": "[\"p\",\"a\",\"strong\"]"
  });
console.log(result.data, result.requestId);

PHP

<?php
require 'vendor/autoload.php';

$h2i = new \Davix\H2I\Client(['apiKey' => getenv('DAVIX_H2I_API_KEY'), 'baseUrl' => getenv('DAVIX_H2I_URL')]);
$result = $h2i->documents()->cleanHtml([
    'html' => '<div onclick="x()"><h1>Title</h1><script>alert(1)</script></div>',
    'mode' => 'sanitize',
    'allow_tags' => '["p","a","strong"]',
]);
echo $result->requestId;
FAQ

Frequently asked questions

Make untidy or untrusted HTML safe and tidy (or take out the article text, plain text or Markdown): an allow-list of tags and attributes, links and pictures treated as you choose, with counts of what was removed.

Clean HTML works from text and settings, so no file is needed. Every input is optional.

Clean HTML is included in every plan, including Free. Each run uses credits from your monthly allowance.

Send a POST request to /v1/documents/clean-html with your API key in the X-Api-Key header. Official SDKs for Node.js, Python, PHP, Go, Java, .NET and Ruby do the same for you, and the code box on this page shows ready-to-copy examples. For large work it can also run as a background job, so your request returns straight away.