{"slug": "html-to-markdown-api-clean-markdown-from-any-web-page", "title": "HTML to Markdown API: Clean Markdown From Any Web Page", "summary": "A developer at APIBox published a guide to the company's /v1/html-to-markdown endpoint, which converts HTML strings or live URLs into clean Markdown with metadata including word and character counts. The API strips script, style, iframe, svg and canvas elements, resolves relative links against a base URL, and offers an optional readability mode built on Mozilla Readability to isolate main article content. The guide demonstrates wiring the endpoint into LLM prompts, scrapers, content migration and HTML email workflows, with a free tier of 1,000 requests per month.", "body_md": "*Disclosure: I work on APIBox, the API used in this guide. The first draft was written with AI assistance; I tested the code and edited it.*\n\nMarkdown has quietly become the exchange format of the AI era. LLMs read it well, it costs far fewer tokens than raw HTML, note apps like Obsidian store it natively, and every static site generator speaks it.\n\nThe web, however, still ships HTML: navigation bars, cookie banners, inline scripts, tracking pixels and a dozen nested `<div>` s around three paragraphs of actual content.\n\nThis guide shows how to use the APIBox `/v1/html-to-markdown` endpoint to turn HTML strings or live URLs into clean Markdown, and how to wire it into four common jobs: LLM prompts, scrapers, content migration and HTML email.\n\nYou send either an `html` string or a public `url`. You get back Markdown plus a little metadata:\n\n`script`, `style`, `iframe`, `svg` and `canvas` elements are dropped.`href` and `src` values are resolved against the fetched URL or your `base_url`.` readability=true` runs Mozilla Readability (the engine behind Firefox Reader View) to keep only the main article and return an `excerpt`.` words` and `characters` let you budget prompt size before you send anything to a model.`heading_style` (`atx` / `setext`), `bullet` (`-`, `*`, `+`), `code_block_style` (`fenced` / `indented`), `link_style` (`inlined` / `referenced`), `keep_links`, `keep_images`.` robots.txt`.\nCreate a free APIBox account (Free plan: 1,000 requests per month, 30 per minute, no card) and generate an API key:\n\n```\nexport APIBOX_KEY=\"your_key_here\"\n```\n\nThe key can go in `Authorization: Bearer`, an `x-api-key` header, or an `api_key` query parameter. Prefer a header so keys don't end up in logs.\n\n```\ncurl -s https://apibox.io.vn/v1/html-to-markdown \\\n  -H \"Authorization: Bearer $APIBOX_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"html\": \"<h1>Getting started</h1><p>APIBox turns <strong>HTML</strong> into clean <a href=\\\"/docs\\\">Markdown</a>.</p><ul><li>Fast</li><li>Simple</li></ul><table><tr><th>Plan</th><th>Requests</th></tr><tr><td>Free</td><td>1,000</td></tr></table>\",\n    \"base_url\": \"https://example.com\"\n  }'\n```\n\nResponse:\n\n```\n{\n  \"title\": \"\",\n  \"markdown\": \"# Getting started\\n\\nAPIBox turns **HTML** into clean [Markdown](https://example.com/docs).\\n\\n-   Fast\\n-   Simple\\n\\n| Plan | Requests |\\n| --- | --- |\\n| Free | 1,000 |\",\n  \"characters\": 162,\n  \"words\": 28\n}\n```\n\nNotice three things: the relative `/docs` link became `https://example.com/docs` thanks to `base_url`, the HTML table became a real Markdown table, and `title` is empty because the fragment has no `<title>` element.\n\nYou can also skip JSON entirely and POST raw HTML with `Content-Type: text/html`:\n\n```\ncurl -s https://apibox.io.vn/v1/html-to-markdown \\\n  -H \"Authorization: Bearer $APIBOX_KEY\" \\\n  -H \"Content-Type: text/html\" \\\n  --data-binary '<h2>Raw</h2><p>Hello <em>world</em></p>'\n{\"title\":\"\",\"markdown\":\"## Raw\\n\\nHello _world_\",\"characters\":21,\"words\":4}\n```\n\nFeeding a whole page's HTML to a model wastes tokens on markup and boilerplate. Fetch it as Markdown with `readability=true`, check the size, then build the prompt:\n\n``` js\nconst KEY = process.env.APIBOX_KEY;\n\nasync function pageAsMarkdown(url) {\n  const r = await fetch('https://apibox.io.vn/v1/html-to-markdown', {\n    method: 'POST',\n    headers: { Authorization: `Bearer ${KEY}`, 'Content-Type': 'application/json' },\n    body: JSON.stringify({ url, readability: true, keep_images: false }),\n  });\n  if (!r.ok) throw new Error(`html-to-markdown ${r.status}: ${await r.text()}`);\n  return r.json(); // { title, markdown, excerpt, words, characters }\n}\n\nconst page = await pageAsMarkdown('https://en.wikipedia.org/wiki/Markdown');\n\n// Rough budget check before calling your model\nif (page.words > 6000) console.warn(`Long page (${page.words} words) – consider chunking`);\n\nconst prompt = `Summarise the article below in 5 bullet points.\\n\\n# ${page.title}\\n\\n${page.markdown}`;\nconsole.log(prompt.slice(0, 500));\n```\n\nWhat came back on 2026-11-25 (first lines of the prompt, then the metadata):\n\n```\nSummarise the article below in 5 bullet points.\n\n# Markdown\n\nFrom Wikipedia, the free encyclopedia\n\n| Markdown |\n| --- |\n| [](https://en.wikipedia.org/wiki/File:Markdown-mark.svg) |\n| [Filename extensions](https://en.wikipedia.org/wiki/Filename_extension \"Filename extension\") | `.md`, `.markdown`[\\[1\\]](https://en.wikipedia.org/wiki/Markdown#cite_note-df-2022-1)… (truncated)\n{ \"title\": \"Markdown\", \"excerpt\": \"From Wikipedia, the free encyclopedia\", \"words\": 3360, \"characters\": 47587 }\n```\n\nAbout 47,000 characters for a long encyclopedia article, well under the 6,000-word warning, so it can go to a model in one piece. Two things to notice: Readability kept the infobox as a Markdown table, and `keep_images: false` removed the logo image but left an empty `[](…)` link where the image had been wrapped in a link. If empty links bother your model, strip `[](...)` with a one-line regex.\n\nWhy these options:\n\n`readability: true` strips nav, footers and sidebars, which are pure noise for a summariser.`keep_images: false` drops image syntax the model can't see anyway.\nIf you are building retrieval (RAG), split on Markdown headings: `##` sections make natural chunks that keep context together.\n\nMany scrapers end with a messy \"extract text\" step. Markdown keeps structure (headings, lists, tables, links) that plain text loses, while staying easy to diff and store:\n\n``` python\nimport os, requests\n\nKEY = os.environ[\"APIBOX_KEY\"]\n\ndef to_markdown(url):\n    r = requests.post(\n        \"https://apibox.io.vn/v1/html-to-markdown\",\n        json={\"url\": url, \"readability\": True, \"link_style\": \"referenced\"},\n        headers={\"Authorization\": f\"Bearer {KEY}\"},\n        timeout=30,\n    )\n    r.raise_for_status()\n    return r.json()\n\ndoc = to_markdown(\"https://keepachangelog.com/en/1.1.0/\")\nwith open(\"changelog.md\", \"w\", encoding=\"utf-8\") as f:\n    f.write(doc[\"markdown\"])\nprint(doc[\"words\"], \"words saved\")\n```\n\nOutput:\n\n```\n1142 words saved\n```\n\nAnd the start and end of `changelog.md`:\n\n```\n### [][1]What is a changelog?\n\nA changelog is a file which contains a curated, chronologically ordered list of notable changes for each version of a project.\n\n### [][2]Why keep a changelog?\n… (truncated)\n```\n\nThe `[][1]` before each heading is the page's own empty anchor link (`<a href=\"#what\">`), kept as a reference.\n\n`link_style: \"referenced\"` moves URLs to the bottom as `[1]: https://...` references, which keeps long documents readable and makes link changes easy to spot in a git diff.\n\nStay on the Free plan's 30 requests/minute by adding a short sleep between URLs, and store results so you don't re-fetch unchanged pages.\n\nMoving from WordPress or a legacy CMS to a static site generator usually means exporting HTML bodies from a database. Send each body with `base_url` set to the old site so images and internal links stay absolute:\n\n```\ncurl -s https://apibox.io.vn/v1/html-to-markdown \\\n  -H \"Authorization: Bearer $APIBOX_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"html\": \"<p>See <a href=\\\"/2019/05/old-post\\\">my old post</a>.</p><img src=\\\"/wp-content/uploads/a.png\\\">\", \"base_url\": \"https://old-blog.example\", \"heading_style\": \"atx\", \"bullet\": \"-\"}'\n{\n  \"title\": \"\",\n  \"markdown\": \"See [my old post](https://old-blog.example/2019/05/old-post).\\n\\n![](https://old-blog.example/wp-content/uploads/a.png)\",\n  \"characters\": 117,\n  \"words\": 5\n}\n```\n\nBoth the link and the image now point at the old domain. Keep it that way while migrating, then search-and-replace the domain once the new site is up. Notice also that the empty `alt` on the image gave `![]`. That is a good moment to fill in missing alt text.\n\nPin `heading_style`, `bullet` and `code_block_style` explicitly so every converted file follows the same style, then run your usual Markdown linter once over the output.\n\nThe same endpoint works for HTML produced by email clients and WYSIWYG editors. A common pattern: store user content as Markdown (easy to diff, search and render anywhere), and convert editor output on save. Pair it with the companion `/v1/markdown-to-html` endpoint, which sanitises output by default, when you need to render it back.\n\nConverting HTML to Markdown is a solved problem in most languages: Turndown in JavaScript, markdownify or html2text in Python, and full open-source services you can self-host. If you already run a Node or Python backend and only convert HTML you control, a library is the simplest choice.\n\nAn API makes more sense when:\n\nThere are other hosted HTML-to-Markdown services too; pick the one whose limits and pricing fit your workload.\n\n**Can I convert a page by URL instead of pasting HTML?**\n\nYes. Send `url` instead of `html`. If both are present, `url` wins (we checked: sending `html: \"<p>X</p>\"` together with `url: \"https://example.com\"` returned the Example Domain text).\n\n**Are HTML tables converted?**\n\nYes. Tables, strikethrough and task lists follow GitHub-flavored Markdown rules.\n\n**How do I remove links or images?**\n\n`keep_links=false` keeps only the link text; `keep_images=false` drops `img`, `picture` and `figure` elements.\n\n**Does it render JavaScript?**\n\nNo. It converts the HTML the server returns. Render client-side apps yourself first, then send the HTML.\n\n**Is there a request size limit?**\n\nHTML up to 5 MB, request body up to 6 MB, and fetched pages are read up to 5 MB.\n\nFree plan: 1,000 requests per month, no credit card.\n\nFull parameter reference: [HTML to Markdown API docs](https://apibox.io.vn/docs/html-to-markdown/?utm_source=devto&utm_medium=community&utm_campaign=html-to-markdown-api). Try it without code: [online HTML to Markdown converter](https://apibox.io.vn/tools/html-to-markdown/?utm_source=devto&utm_medium=community&utm_campaign=html-to-markdown-api).", "url": "https://wpnews.pro/news/html-to-markdown-api-clean-markdown-from-any-web-page", "canonical_source": "https://dev.to/solplify/html-to-markdown-api-clean-markdown-from-any-web-page-55e6", "published_at": "2026-11-28 17:06:28+00:00", "updated_at": "2026-11-28 17:13:48.138410+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "large-language-models", "ai-agents"], "entities": ["APIBox", "Mozilla Readability", "Obsidian"], "also_reported_by": [], "takeaway": "APIBox's /v1/html-to-markdown endpoint with readability=true returns only main article content plus word and character counts, letting you budget prompt size before sending a page to a model.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/html-to-markdown-api-clean-markdown-from-any-web-page", "markdown": "https://wpnews.pro/news/html-to-markdown-api-clean-markdown-from-any-web-page.md", "text": "https://wpnews.pro/news/html-to-markdown-api-clean-markdown-from-any-web-page.txt", "jsonld": "https://wpnews.pro/news/html-to-markdown-api-clean-markdown-from-any-web-page.jsonld"}}