Simple EPUB Guide

This document describes an ebook adhering to EPUB v3.2. It was last updated on August 30, 2022.

This document assumes familiarity with HTML and the ability to execute zip commmands via a CLI.

The EPUB file format describes ebooks. It is a zipped archive of various XML and XHTML files. The archive should contain a file called mimetype; a directory called META-INF with a file called container.xml; and a content directory with at least one content file, a navigation file, and a package file (.opf).


The mimetype file contains the MIME type for the EPUB file. It contains the string, application/epub+zip and nothing else. Not even a newline. You can create it with the following— echo -n 'application/epub+zip' > mimetype

You should start your EPUB file with the following command— zip -X0 FILENAME.epub mimetype This part of the EPUB file is uncompressed.


The META-INF directory contains XML files which describe the ebook. The ebook's content goes into a diferent directory. At a minimum, this directory must have a file called container.xml.


<?xml version="1.0" encoding="UTF-8"?> <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> <rootfiles> <rootfile full-path="OPS/book.opf" media-type="application/oebps-package+xml"/> </rootfiles> </container>

See W3C for more info.


The content directory holds the ebook's content. This directory can be called anything, but OEBPS, OPS, and EPUB are customary.


The OPF file (Open Package Format) contains metadata about the ebook, the ebook's manifest, and the spine which is a list of the book's items in the order they should be presented to the reader. Notice that the table of contents is not in the spine. It is handled separately by the ebook reader.

<?xml version="1.0" encoding="UTF-8"?> <package version="3.0" xmlns="" unique-identifier="pub-id"> <metadata xmlns:dc="" xmlns:opf=""> <dc:title>Nursery Rhymes</dc:title> <dc:creator id="creator">Various Authors</dc:creator> <dc:identifier id="pub-id">A Unique ID</dc:identifier> <dc:language>en</dc:language> <meta property="dcterms:modified">2022-08-14T00:00:00Z</meta> </metadata> <manifest> <item id="titlePage" href="titlePage.xhtml" media-type="application/xhtml+xml" /> <item id="toc" href="toc.xhtml" media-type="application/xhtml+xml" properties="nav"/> <item id="ch1" href="ch1.xhtml" media-type="application/xhtml+xml" /> <item id="ch2" href="ch2.xhtml" media-type="application/xhtml+xml" /> <item id="ch3" href="ch3.xhtml" media-type="application/xhtml+xml" /> </manifest> <spine> <itemref idref="titlePage" /> <itemref idref="ch1" /> <itemref idref="ch2" /> <itemref idref="ch3" /> </spine> </package>

The title page, table of contents, and each chapter are just regular XHTML files. Examples below.

Title Page

<?xml version="1.0" encoding="UTF-8"?> <html xml:lang="en" xmlns=""> <head> <title>Nursery Rhymes</title> <meta charset="UTF-8" /> </head> <body> <h1>Nursery Rhymes</h1> <h2>by Various Authors</h2> </body> </html>

Table of Contents

<?xml version="1.0" encoding="UTF-8"?> <html xml:lang="en" xmlns:epub="" xmlns=""> <head> <title>Nursery Rhymes</title> <meta charset="UTF-8"/> </head> <body> <nav epub:type="toc" id="toc"> <ol> <li><a href="titlePage.xhtml">Title</a></li> <li><a href="ch1.xhtml">Mary Had a Little Lamb</a></li> <li><a href="ch2.xhtml">Simple Simon</a></li> <li><a href="ch3.xhtml">Old Mother Hubbard</a></li> </ol> </nav> </body> </html>

Chapter 1

<?xml version="1.0" encoding="UTF-8"?> <html xml:lang="en" xmlns=""> <head> <title>Mary Had a Little Lamb</title> <meta charset="UTF-8"/> </head> <body> <h1>Mary Had a Little Lamb</h1> <p>Mary had a little lamb.</p> <p>It's fleece was white as snow.</p> <p>And everywhere that Mary went.</p> <p>The Lamb was sure to go.</p> </body> </html>

You can finish creating your EPUB with the following command— zip -rDX9 FILENAME.epub META-INF OPS It's assumed you already created FILENAME.epub earlier and is in the same directory as META-INF and OPS.

After you create your epub, you can validate it with epubcheck and Kindle Previewer.

You can download my curated list of nursery rhymes (NurseyRhymes.epub) and view it on your favorite ereader or you can unzip it to see all of the files that were just discussed. You should put the epub file in a separate directory before you unzip it.

See also... EPUB on Wikipedia W3C EPUB 3 Overview