To convert HTML to Markdown, install Pandoc, then run pandoc -f html -t markdown page.html -o page.md in your terminal. Check the result afterwards, because complex tables and some layout may not survive the conversion.
The short answer on what Pandoc does
Pandoc is a command line converter, and it'll turn a saved HTML file or a live web page into a Markdown file you can edit.
Steps to convert HTML to Markdown with Pandoc
- Install Pandoc, then open a terminal in the folder that holds your HTML file.
- Run
pandoc -f html -t markdown page.html -o page.md. The-fflag names the input format and-tnames the output. If you leave both out, Pandoc tries to guess the formats from the file extensions. - Keep the
-o(or--output) part. Without it, the Markdown is printed to the terminal window (stdout) rather than saved as a file. - Want GitHub style output? Swap
-t markdownfor-t gfm, which is GitHub-Flavored Markdown. Don't reach for the oldermarkdown_githubformat, as it's deprecated and less accurate. - To convert a live web page, give its address where the file name would go and Pandoc fetches it over HTTP. Pandoc's own demos page uses
pandoc -s -r html https://pandoc.org/ -o example12.text. If the site needs a custom User-Agent or another header, add--request-header. - Add
--wrap=noneto stop line wrapping and--extract-media=mediato save images and other media into a folder. Pandoc adjusts the image references in the Markdown to point at those saved copies, and it can write them to a zip in place of a folder. - Open the new Markdown file and check the headings, links, tables and images before you use it.
Once the file is converted, you'll want somewhere comfortable to edit it. My roundup of the best Markdown editors covers the options, and if you're on a Mac, this list of Markdown editors for Mac narrows it down. Need the content back out as a document to share? These Markdown to PDF converters handle that next step.
When the output doesn't look right
Lines break in odd places. The --wrap option takes auto, none or preserve. Auto is the default and wraps text to 72 columns unless you change that with --columns. Use none to stop line wrapping; preserve is the third option.
Headings use a different style from the one you want. --markdown-headings picks between atx and setext headings. Atx, where each heading starts with # signs, is the default.
Links clutter the text. Pandoc writes inline links by default. Add --reference-links and it'll write reference style links instead.
Odd characters appear. Pandoc uses UTF-8 for input and output. If your HTML is saved in another encoding, pipe it through iconv first.
Want AI doing the heavy lifting in your marketing?
I build the systems that handle the boring 80 percent, so you get your week back. Done properly, with the human kept in.
Your table broke. Complex tables may not fit Pandoc's document model, so check every table against the original page. Rebuild it by hand in the Markdown, or keep it as HTML. On that last point, the raw_html extension, which keeps HTML that Markdown can't represent as raw HTML, is switched off by default when the input is HTML.
What Pandoc won't carry across
According to Pandoc's documentation, it keeps structural elements, but not presentation details like margin size, and conversions can be lossy.
Don't assume menus, sidebars or scripts on a web page will be stripped out either. When you convert a live page, expect to tidy the file and delete the navigation text by hand.
If you're converting HTML you didn't write, or a page from a site you don't control, the documentation says anyone using Pandoc on untrusted input should add --sandbox.
The converter I'd reach for
Run Pandoc with -t gfm, --wrap=none and --extract-media=media on one command, then read the file line by line before publishing it. Leave time for fixing tables and cutting leftover menu text, because that part's on you.


