HTML to EPUB: Convert Web Pages and HTML Files (2026)
November 11, 2026 · 9 min read
HTML to EPUB: Turn Web Pages and HTML Files Into an Ebook
Converting HTML to EPUB works best in two moves. First clean the HTML and split it into chapters, then let a packager build the book. Pandoc and Calibre do the packaging from the command line. For messy web articles, a quick detour through Markdown strips the site clutter before you build the EPUB.
What an EPUB Needs From Your HTML
An EPUB is a ZIP container of web documents plus a package file that lists them in reading order. So is an EPUB just HTML? Close, but stricter. The EPUB 3.3 specification, the current W3C Recommendation, sets three rules that decide whether an HTML to EPUB conversion goes smoothly:
- Content documents are XHTML. They use HTML's XML syntax, so every tag closes and every attribute is quoted. A browser forgives
<p>One<br>Two, but XHTML needs<p>One<br/>Two</p>. - The navigation document holds exactly one
tocnav. That's the table of contents a reading app shows. - Images and CSS live inside the package. The spec lets audio, video, fonts and files that scripts fetch stay remote. Everything else, images and CSS included, has to sit in the container.
Here's what that table of contents looks like inside the book:
<nav epub:type="toc" id="toc">
<h1>Contents</h1>
<ol>
<li><a href="chapter-01.xhtml">Leaving Port</a></li>
<li><a href="chapter-02.xhtml">Open Water</a></li>
</ol>
</nav>
The epub:type attribute adds structural meaning, such as toc or chapter, that reading systems can act on. You rarely write this file by hand. The converters below generate it from your headings, which is why clean headings matter more than anything else.
Converting One HTML File to EPUB With Pandoc
Pandoc reads HTML directly and writes EPUB 3 by default. For a single saved page, one command is enough:
pandoc article.html -o article.epub --metadata title="The Logbook" --css=book.css --epub-cover-image=cover.jpg
That gives you article.epub with your title, your stylesheet and a cover page. Without --metadata title, Pandoc takes the book title from the page's <title> tag, which on many sites includes the site name. It also rewrites the markup as valid XHTML, closing tags like <br> for you.
Chapters come from headings. Per the Pandoc manual, --split-level defaults to level-1 headings, and --split-level=2 splits at H2 as well. One surprise from our tests: any text before the first H1, such as a site menu, becomes its own short chapter. Strip it first. For Pandoc's other options, see our Pandoc Markdown guide.
How Do You Convert Multiple HTML Files Into One EPUB?
With Pandoc, list the files in reading order. It joins them before parsing, and each H1 starts a new chapter:
pandoc chapter-01.html chapter-02.html chapter-03.html -o book.epub --metadata title="The Logbook"
Calibre's ebook-convert takes a different approach. Give it one entry page and it follows the links to the other files.
ebook-convert index.html book.epub --max-levels 2 --level1-toc "//h:h1"
According to the ebook-convert reference, --max-levels sets how deep it follows links (default 5, and 0 means it follows none). It walks links depth first unless you add --breadth-first, so a page linked from chapter 1 can land before chapter 2. Calibre's FAQ suggests an index page that links every file in the order you want. It also accepts a ZIP of the whole folder as input. The --level1-toc XPath puts every H1 in the table of contents.
Can You Convert a Web Page to EPUB?
Yes, but get the page onto your machine in a usable state first. You have two choices:
- Save it from the browser. Use your browser's save option to keep the HTML and its images, then run Pandoc or Calibre on the local file.
- Fetch it by URL. Pandoc accepts an absolute URL in place of an input file and fetches it over HTTP, as in
pandoc https://example.com/post -o post.epub.
Either way, you get the whole page: menus, cookie banners, share buttons and related-post lists. Pages that build their content with JavaScript, or sit behind a login, often arrive half empty when fetched.
Our URL to Markdown tool takes the fetch route and gives you Markdown instead of HTML. It runs on our server with no JavaScript rendering and turns the page title into the H1. It keeps the full body, so navigation and footers come along for you to delete. Each successful conversion uses 1 of the 3 free server operations per day. The website to Markdown guide covers that step in depth.
Cleaning HTML Through Markdown Before Packaging
Web HTML is mostly presentation: wrapper divs, inline styles, ad slots and tracking markup. Converting it to Markdown throws all of that away and leaves headings, paragraphs, lists, links and images. What remains is short enough to fix by hand in a few minutes.
Open the saved page in a text editor (or your browser's view-source), copy the HTML and paste it into our HTML to Markdown converter. It converts in your browser with no daily limit and loads the Markdown into an editor. Then do three jobs: delete the clutter, make every chapter title an H1, and check image links. Here's a typical result before cleanup.
[Home](/) | [Archive](/archive) | [About](/about)
Posted by Sam, 6 min read
**Part 2: Open Water**
By day four the routine felt normal.
Share this post: [Email](mailto:?subject=Logbook)
And here it is after cleanup, ready to become a chapter.
# Part 2: Open Water
By day four the routine felt normal.
The bold line that only looked like a heading is now a real H1, and the menu and share links are gone. For other ways to do the conversion itself, see how to convert HTML to Markdown.
We prefer this Markdown round trip for articles and blog posts, because it drops clutter and inline styles that would otherwise follow you into the book. For clean HTML you wrote yourself, go straight to Pandoc.
Here's one chapter in the shape your text should have before packaging. The H1 opens the chapter and the H2 stays inside it as a section. Add the next chapter below it with another H1.
Packaging the Cleaned Markdown as an EPUB 3 File
Copy the cleaned Markdown into our Markdown to EPUB tool. It runs in your browser and splits chapters at H1 (or H2). It also takes book metadata like the title and author, plus an optional cover image you upload, then builds an EPUB 3 file.
On our site, then, HTML to EPUB is two tools, not one: HTML to Markdown, then Markdown to EPUB. If you'd rather script it, pandoc book.md -o book.epub does the same packaging from a terminal.
Why Are Images Missing After Converting HTML to EPUB?
Images go missing because the converter couldn't find the files to copy into the book. The usual causes:
- Relative paths resolve from the wrong folder. Pandoc looks for
images/map.pngrelative to the folder you run it from, not the HTML file's folder. Add--resource-path=site(the folder holding the HTML) to fix it. - Lazy-loaded images. Some sites put the real image address in a data attribute and swap it in with JavaScript. A converter that doesn't run scripts sees only the placeholder, so copy the data attribute's address into the image's
srcbefore converting. - Images left as remote links. Pandoc downloads images at absolute URLs into the EPUB. Our Markdown to EPUB tool doesn't.
That last point is this route's real limitation. Our EPUB tool doesn't fetch or embed images linked by URL. Only the uploaded cover goes into the book. For an image-heavy article, run Pandoc on the cleaned Markdown, or download the images and convert local files.
Testing the Finished Ebook Before You Read It
A conversion that finishes without errors can still produce a book with gaps. Spend five minutes on these checks:
- Open the table of contents. Each entry should match one of your H1s, with no stray chapter named after the site menu.
- Turn the font size up two steps. Text should rewrap, and wide tables or code blocks shouldn't run off the screen.
- Page through every image, especially in the last chapters.
- Validate the file with EPUBCheck, the open source checker the DAISY Consortium maintains on behalf of W3C. It runs on Java.
java -jar epubcheck.jar book.epub
EPUBCheck lists each error and warning along with where it found it. Leftover HTML that isn't valid XHTML shows up here as an error.
Quick Answers on HTML to EPUB Conversion
HTML to EPUB conversion comes down to clean input. Strip the site clutter, give each chapter an H1, keep images where the converter can find them, and Pandoc or Calibre handles the rest. For web articles, paste the HTML into our HTML to Markdown converter, tidy it in the editor, and build the book with the Markdown to EPUB tool. You can also draft or fix chapters in the editor first.