# Convert HTML to Markdown for LLMs and RAG

Turn HTML into clean Markdown for LLM context, RAG and agents. Convert any URL with Webcrawl via API, MCP or CLI. Free credits to start.

Developers building LLM context, RAG indexes and agents need clean Markdown from web pages, not raw HTML soup. HTML to Markdown is that transform: we read the page markup, keep the structure models can use, and emit compact text you can chunk, embed and cite.

Why Markdown for LLMs? HTML carries scripts, styles and layout wrappers that burn tokens without helping reasoning. Markdown keeps headings, lists, links, tables and code with fewer characters, and it matches how teams already paste docs into prompts. Heading-aware chunkers also split Markdown more reliably than noisy DOM trees.

How to convert HTML to Markdown with Webcrawl: give us a public URL. POST /v1/scrape fetches the page and returns a markdown field (full page by default). The same scrape path is available over REST, @webcrawl/client, the webcrawl CLI (webcrawl scrape <url>), and @webcrawl/mcp (web_read). For a one-off preview, use the free website to Markdown tool. For production RAG and agents, use an API key or MCP with the hosted product (1,000 free credits a month) or self-host the MIT engine.

Set onlyMainContent to true when you want navigation, headers and footers trimmed. Use includeTags and excludeTags for tighter control, and retainImages when images matter. Matching /v2/scrape and /api/v1/scrape aliases exist. Pair scrape with map or crawl when you need many URLs, and with extract when fields must be JSON instead of prose.

HTML to Markdown is the core step behind website to Markdown APIs and many scrape tools built for LLMs. It is necessary for clean context, and works best with the right URL set (map, search, crawl), a refresh strategy, and optional structured extract. See /url-to-markdown for the full scrape product path, and the scrape docs for request fields.

## What HTML to Markdown keeps and strips

Webcrawl keeps headings (h1 through h6 as ATX # lines), paragraphs, links with absolute targets, lists, pipe-style tables, blockquotes, bold and italic, inline code, and fenced code from pre/code blocks. Images become Markdown image links when retainImages is all (the default). Scripts, styles, noscript, svg, canvas, template and iframe blocks are stripped. With onlyMainContent set to true, we prefer main or article content and drop header, footer, nav and aside chrome. The goal is stable semantics for LLM context, not a pixel-perfect clone of the page.

### Example: HTML in, Markdown out

```
<!-- Input HTML -->
<article>
  <h1>Getting started</h1>
  <p>Install the <a href="/cli">CLI</a> and scrape a URL.</p>
  <ul><li>Create an API key</li><li>Call POST /v1/scrape</li></ul>
  <pre><code>npx webcrawl scrape https://example.com</code></pre>
</article>

<!-- Output Markdown -->
# Getting started

Install the [CLI](https://example.com/cli) and scrape a URL.

- Create an API key
- Call POST /v1/scrape

```
npx webcrawl scrape https://example.com
```
```

## Convert a URL to Markdown with scrape

```
curl -s -X POST https://webcrawl.app/v1/scrape \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/docs/getting-started"}'

# Same path via CLI
npx webcrawl scrape https://example.com/docs/getting-started
```

## FAQ

### How do I convert HTML to Markdown with Webcrawl?

Call POST /v1/scrape with a public URL, run npx webcrawl scrape <url>, use @webcrawl/client scrape, or call web_read over @webcrawl/mcp / hosted MCP. The response includes a markdown field ready for LLM context and RAG.

### Do I convert a URL or paste raw HTML?

Pass a public URL. Webcrawl fetches the page HTML and returns clean Markdown. The free tool at /tools/website-to-markdown works the same way for capped previews. For many pages, map or crawl first, then scrape the URLs you need.

### Why use Markdown instead of HTML for LLMs?

Markdown keeps headings, lists, links, tables and code with fewer tokens than raw HTML, so models spend context on content instead of scripts and layout. It also chunks cleanly for RAG and matches how developers already paste docs into prompts.

### Is HTML to Markdown free and open source?

Yes. The engine is MIT licensed at https://github.com/brainfish-ai/webcrawl-anything. Hosted accounts include 1,000 free credits a month with no card. The website to Markdown tool offers a capped free preview of the same scrape path.

### Where is the full URL to Markdown API guide?

See /url-to-markdown for the product guide, /docs/scrape for request fields, and /scrape for the product overview. Related glossary: LLM-ready Markdown.

Related: [URL to Markdown](https://webcrawl.app/url-to-markdown), [Scrape docs](https://webcrawl.app/docs/scrape), [LLM-ready Markdown](https://webcrawl.app/glossary/llm-ready-markdown), [Website to Markdown](https://webcrawl.app/tools/website-to-markdown), [HTML to Markdown tool](https://webcrawl.app/tools/html-to-markdown), [Jina Reader alternative](https://webcrawl.app/alternatives/jina-reader), [PDF to Markdown tool](https://webcrawl.app/tools/pdf-to-markdown), [DOCX to Markdown tool](https://webcrawl.app/tools/docx-to-markdown), [Documentation ingestion](https://webcrawl.app/use-cases/documentation-ingestion), [RAG knowledge base](https://webcrawl.app/use-cases/rag-knowledge-base).

HTML: https://webcrawl.app/glossary/html-to-markdown
