HTML to Text API
Strip tags from HTML or a web page URL and get readable plain text with line breaks preserved, plus word and character counts.
Send HTML in the html field (JSON, form or query string), as a raw text/html body, or give a public url to fetch. The API removes script, style, noscript, template and head content, turns <br> and block elements (paragraphs, headings, list items, table rows, divs...) into line breaks, collapses repeated spaces and returns the text with its characters and words counts.
Unlike HTML to Markdown, no formatting is kept: the result is plain text suitable for search indexing, previews, SMS or text-only emails.
Limits: HTML up to 5 MB (request body up to 6 MB); URLs are fetched up to 5 MB with a 10 second timeout and at most 8 redirects. Only public http/https hosts are allowed.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
html | body|query | string | no | HTML to convert (max 5 MB). Can also be sent as a raw text/html body. Required unless url is given. | |
url | body|query | string | no | Public http/https URL of a page to fetch (takes precedence over html). |
Example
curl -X POST "https://apibox.io.vn/v1/html-to-text" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html":"<h1>Order confirmed</h1><p>Thanks for your order, <b>Alice</b>.<br>It ships tomorrow.</p><ul><li>1 x Keyboard</li><li>2 x Mouse</li></ul><style>p{color:red}</style>"}'const res = await fetch('https://apibox.io.vn/v1/html-to-text', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"html": "<h1>Order confirmed</h1><p>Thanks for your order, <b>Alice</b>.<br>It ships tomorrow.</p><ul><li>1 x Keyboard</li><li>2 x Mouse</li></ul><style>p{color:red}</style>"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/html-to-text",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"html": "<h1>Order confirmed</h1><p>Thanks for your order, <b>Alice</b>.<br>It ships tomorrow.</p><ul><li>1 x Keyboard</li><li>2 x Mouse</li></ul><style>p{color:red}</style>"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/html-to-text');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"html":"<h1>Order confirmed</h1><p>Thanks for your order, <b>Alice</b>.<br>It ships tomorrow.</p><ul><li>1 x Keyboard</li><li>2 x Mouse</li></ul><style>p{color:red}</style>"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"text": "Order confirmed\nThanks for your order, Alice.\nIt ships tomorrow.\n1 x Keyboard\n2 x Mouse",
"characters": 87,
"words": 16
}
Use cases
- Build the plain-text part of an HTML email
- Index web page content in a search engine or database
- Create text previews and snippets from rich content
- Count words of a web page or article
FAQ
Are line breaks preserved?
Yes. <br> and block elements such as p, div, li, headings and table rows produce new lines; three or more blank lines are collapsed.
Is JavaScript and CSS content removed?
Yes. script, style, noscript, template and head elements are removed before the text is extracted.
Can I extract text directly from a URL?
Yes. Send url instead of html; the page is fetched (up to 5 MB) and converted.
Related APIs
HTML to Markdown
Convert HTML or any web page URL into clean GitHub-flavored Markdown, with tables, optional article extraction and absolute links.
</>Markdown to HTML
Render GitHub-flavored Markdown to HTML with tables and strikethrough. Output is sanitized by default to strip scripts and event handlers.
<✓>HTML Sanitizer
Strip scripts, iframes, forms, event handlers, inline styles and javascript: links from untrusted HTML before you display it.