Markdown vs HTML for AI Prompts: Which Saves More Tokens?
Markdown is roughly half the tokens of equivalent HTML and survives the round-trip into LLMs better. Here's the data, and how to convert any source into clean Markdown for prompts.
If you're pasting copied web content or rich-text documents into a prompt, you're probably wasting tokens. HTML carries enormous overhead — class attributes, inline styles, tracking spans, wrapper divs — that adds nothing to what the model can extract from the content.
The token comparison, with numbers
We took the same 10 articles from major news sites and counted tokens (using the GPT-4 tokenizer):
- Average raw HTML: 8,400 tokens
- Same content as cleaned Markdown: 4,100 tokens
- Same content as plain text: 3,600 tokens
Markdown is the sweet spot — slightly heavier than plain text but preserving headings, lists, links, and code blocks the model can use as structural cues.
Why models read Markdown better
Every major LLM's training corpus is dominated by Markdown sources: GitHub README files, Stack Overflow answers, technical documentation, blog posts. The model has learned what ##, *, and triple-backtick code fences mean as well as any English word. By contrast, complex HTML with class names and inline style attributes is comparatively rare in training data and adds noise.
What to convert, and how
Markdown Converter takes HTML, copied web pages, or rich-text and gives back tidy Markdown. It preserves:
- Heading hierarchy (h1–h6)
- Ordered and unordered lists
- Links with anchor text
- Inline and fenced code
- Block quotes
And drops everything else: classes, IDs, inline styles, tracking attributes, social embed wrappers.
Special cases worth knowing
Tables
Markdown tables are great for up to 4–6 columns. Wider tables become illegible; keep them as HTML or, better, transform them into a list of objects ("Row 1: A=…, B=…").
Math and formulas
Use LaTeX wrapped in $...$ or $$...$$ blocks. Both ChatGPT and Claude render this correctly when echoed back.
Code blocks
Always include a language tag after the opening fence (```python, ```typescript). It improves both rendering and the model's ability to reason about syntax.
The compounding effect
Halving your input tokens halves your input cost on every API call, doubles your effective context room, and reduces latency. After conversion, run very long inputs through Context Compressor for a second-pass squeeze.
Tools mentioned
Frequently asked
Does the model actually read Markdown better?
Yes. The training corpora of every major LLM contain enormous amounts of GitHub README, Stack Overflow, and technical docs — all Markdown. The structural cues (#, *, ```) are deeply learned.
What about JSON?
JSON is great for structured data exchange but token-heavy for prose. Use it for inputs/outputs you'll parse, Markdown for content the model should read.
Should I keep tables in Markdown or HTML?
Markdown tables for narrow ones; HTML for tables wider than ~6 columns. Models handle both, but wide Markdown tables become unreadable.
Keep reading
How to Prepare PDFs for ChatGPT, Claude, and Gemini
A practical guide to extracting clean, AI-ready text from PDFs — born-digital and scanned — so ChatGPT, Claude, and Gemini answer accurately and don't waste tokens on headers, footers, and page numbers.
The Best Way to Feed Long Documents to Claude (and Other Long-Context Models)
Claude's 200K-token context is generous, but you'll still want to clean, compress, and structure long documents before sending them. Here's a step-by-step playbook.
Cleaning Whisper Transcripts for AI Summaries
OpenAI Whisper, Otter, and YouTube transcripts are full of timestamps, filler words, and speaker noise. Here's how to strip them before sending to ChatGPT or Claude — and why it matters.