HTML to Markdown: convert web pages and HTML files
Convert HTML to Markdown with Pandoc, Turndown, markdownify or copy and paste, remove page clutter first, and fix the tables and tags left behind.

To convert HTML to Markdown, run Pandoc on the file: pandoc -f html -t gfm page.html -o page.md turns headings, lists, links, emphasis, images and simple tables into GitHub Flavored Markdown. For a web page, save or copy only the article first, because navigation, footers and cookie banners convert too. For a one-off, copying the text from the browser and pasting it into an editor that converts rich text is often quicker than either.
This guide covers Pandoc, the two libraries most code uses (Turndown for JavaScript and markdownify for Python), and the cleanup that every method needs. The Pandoc details come from the Pandoc manual (checked November 2026).
How do you convert an HTML file with Pandoc?
Install Pandoc from the installing page, or run brew install pandoc on a Mac, then:
pandoc -f html -t gfm --wrap=none page.html -o page.md
| Part | Meaning |
|---|---|
-f html |
Read HTML |
-t gfm |
Write GitHub Flavored Markdown, which has tables and task lists |
--wrap=none |
Keep each paragraph on one line instead of wrapping at 72 columns |
-o page.md |
The file to write |
Pandoc can also fetch a page directly when you give it a URL instead of a file name:
pandoc -f html -t gfm --wrap=none https://example.com/post -o post.md
By default, anything Pandoc can't express in Markdown is kept as raw HTML: <div> wrappers, <span> tags with classes, tables with merged cells. To drop those tags and keep only their text, turn off raw HTML in the output format:
pandoc -f html -t gfm-raw_html --wrap=none page.html -o page.md
That gives a cleaner file, but a complex table is then replaced by a placeholder rather than kept, so check the result for tables before you rely on it.
Why does a converted web page contain so much clutter?
A converter turns everything in the HTML into Markdown, and a typical article page is mostly not the article. Menus become long lists of links, the footer becomes a dozen short paragraphs, and sharing buttons become stray images.
Remove the clutter before converting, not after:
- Use your browser's reader view (available in Safari, Firefox and Chrome under different names), then copy the article from there.
- Save only the main element. In the browser's developer tools, right-click the
<article>or<main>element, copy its outer HTML, and save that aspage.html. - Select the text by hand from the title to the last paragraph and copy it, then paste into a converting editor.
Each of these leaves a short HTML document that converts into a short Markdown file.
How do you convert HTML to Markdown in code?
For scripts and apps, use a library rather than calling Pandoc for every page.
In JavaScript, Turndown is the common choice, with a plugin for GitHub tables and strikethrough:
import TurndownService from "turndown";
import { gfm } from "turndown-plugin-gfm";
const turndown = new TurndownService({ headingStyle: "atx", codeBlockStyle: "fenced" });
turndown.use(gfm);
const markdown = turndown.turndown(html);
In Python, markdownify does the same job:
from markdownify import markdownify
markdown = markdownify(html, heading_style="ATX")
Both default to underlined headings, an older Markdown style, so set atx headings (lines starting with #) explicitly. In Turndown, turndown.remove(["script", "style"]) drops those tags together with their content.
What happens to tables, images and styling?
HTML can express far more than Markdown, so some things convert cleanly and some can't convert at all.
| In the HTML | In the Markdown |
|---|---|
<h1> to <h6> |
# to ###### headings |
<strong>, <em>, <a>, <ul>, <ol> |
Standard Markdown |
<pre><code> |
A fenced code block, with the language if the class names it |
A simple <table> with a header row |
A pipe table |
A table with colspan, rowspan or lists in cells |
Raw HTML, or text only |
<img> |
, still pointing at the original web address |
| Inline styles, colors, fonts | Dropped |
<details>, <sup>, <kbd> |
Raw HTML, or plain text if raw HTML is turned off |
<script>, <iframe>, forms |
Dropped or left as raw HTML, depending on the tool |
Images. Converters keep the image's web address. If you want a lasting copy, download the images into a folder next to the note and change each path to a relative one. Pandoc's --extract-media=media option saves images it can fetch and rewrites the paths for you.
Links. Relative links such as /pricing only work on the original site. Turn them into full addresses if the note will live elsewhere; the Markdown links page shows both forms.
Leftover HTML. Raw HTML is valid inside a Markdown file, but editors and renderers treat it differently. The HTML in Markdown page covers which tags usually survive.
Can you convert HTML to Markdown by copying and pasting?
Yes. When you copy from a web page, the browser puts two versions on the clipboard: plain text and the HTML of the selection. Markdown editors that convert pasted formatting read the HTML version and write Markdown, so headings, lists, links and tables arrive formatted. Paste into a plain text editor and you only get the words.
Copy and paste suits a page or two. Use Pandoc or a library when you have many pages, when you want images saved as files, or when you need the same result every time.
How do you check the converted Markdown?
Whatever method you use, look for the same problems:
- Search for
<to find raw HTML that came through, and decide whether to keep it. - Look for links whose address starts with a slash, such as
/pricing. They break outside the original site. - Check that the first heading is the article's title and not the site name.
- Look for empty links and lone image lines left by buttons and icons.
- Confirm that code blocks kept their line breaks and indentation.
If the source was a chat answer or other generated text, the same checks apply, and cleaning up AI Markdown covers the problems specific to it.
Common questions
Can Pandoc convert a whole website?
Not by itself. Pandoc converts the pages you give it and does not follow links. Download the pages first, for example with wget --mirror --convert-links --no-parent https://example.com/docs/, then run Pandoc on each .html file in a loop.
Which Markdown flavor should the output be?
Pick the flavor of the place the file is going. -t gfm suits GitHub, most note apps and most editors. -t commonmark writes strict CommonMark, which has no table syntax, so tables come out as HTML. -t markdown writes Pandoc's own flavor, which can keep extra details such as heading IDs and classes in curly braces, but other tools may show those braces as text.
HTML to Markdown in Noteline
Noteline, which we make, converts on paste: copy from a web page and paste into an empty note, and the HTML on the clipboard becomes Markdown in the app. Headings, lists, links, checkboxes and tables convert; content inside a collapsible <details> block becomes plain paragraphs; and if the copied headings start at level 2 or skip a level, they are renumbered to start at # and step down one level at a time. Pasting into a note that already has text, or with Cmd+Shift+V (Ctrl+Shift+V on Windows and Linux), inserts plain text instead. Images keep their Markdown link but show only their alt text in the editor.