How to convert HTML to Markdown
Converting HTML to Markdown is one of the most common tasks in web scraping and AI pipelines. But there's a big difference between converting a code block you already have and converting alive web page on the internet — and the right tool depends on which you're doing. Here's the practical breakdown.
Option 1: Convert a URL (the common case)
Most of the time you have a web address, not a blob of HTML. A scraping API fetches the page, renders any JavaScript, strips the boilerplate, and returns clean markdown — all in one call. This is what you want when the target is a live site, a SPA, or anything with a paywall or bot protection.
curl -X POST https://fastcrawl.net/api/v1/scrape/ \\
-H "Authorization: Bearer ***" \\
-H "Content-Type: application/json" \\
-d '{"url":"https://example.com/article","formats":["markdown"]}'Option 2: Convert HTML you already have
If the HTML is already in a variable or file on your side, you don't need a network call — a small library does it in-process. In Python, html2text and markdownify are the standards; in Node, turndown. These are pure text transforms: they don't render JavaScript, so they only work on HTML that's already fully rendered.
python -m pip install markdownify
from markdownify import markdownify as md
html = "<h1>Hello</h1><p>World</p>"
print(md(html))Why a library isn't always enough
A converter only transforms what you hand it. If the page you want renders its content client-side (React, Vue, Next.js), a library sees an empty shell with a root div — there's nothing useful to convert. That's the case where you need something that also runs the page's JavaScript before extracting, which is what a browser-rendering scraping API does for you.
Try it free, no code
If you just want to convert a single page right now, our free converter does it without signup.
Open the free HTML → Markdown converter
Need it at scale? Fastcrawl's API converts any URL to clean, LLM-ready markdown — one flat credit per page, 2,000 credits free a month.
Get a free API key