Making an EPUB File

We have discussed most of the types of files that occur in an EPUB document. The main content is contained in the HTML files. The appearance can be modified by using CSS style files. The other files are organizational. It is useful to have both an NCX table of contents and an HTML table of contents. The HTML table of contents contains links to the various sections of the document and can be seen as you page through the document. An example HTML table of contents is shown below.

<html xmlns="​1999/xhtml" xml:lang="en">


<title>Table of Contents</title>


p {margin-bottom: 1em; text-align: left}

p.ind {margin-left: 2em;}




<p><a href="intro.html">​Introduction<​/a></p>

<p><a href="chap1.html">Chapter 1</a></p>

<p><a href="chap2.html">Chapter 2</a></p>

<p class="ind"><a href="chap2.html#sect1"> ​Section 2.1</a></p>

<p class="ind"><a href="chap2.html#sect2"> ​Section 2.2</a></p>

<p><a href="chap3.html">Chapter 3</a></p>

<p><a href="chap4.html">Chapter 4</a></p>

<p><a href="chap5.html">Chapter 5</a></p>

<p><a href="refs.html">References ​ </a></p>



This code will produce the following table of contents


Chapter 1

Chapter 2

Section 2.1

Section 2.2

Chapter 3

Chapter 4

Chapter 5


You can also have an HTML cover page if you wish. This is a standard XHTML file with the cover image specified in the tag

<img src="…" alt="…" style="height: 100%;" />

The size requirements for covers change fairly often, so it is best to check with the publisher for the current requirements. The last I heard Amazon wanted a 1688x2700 pixel Jpeg image.

The final step in making an EPUB document is to zip the files into a file with extension .epub, e.g., MyBook.epub. There is one caveat. The file mimetype must be the first file added and it must be placed in the EPUB file uncompressed. Not all zip programs do this easily. One program that does this is the command line program zip.exe that can be downloaded from the site​index.php?tool=zipunzip. To add mimetype to the file MyBook.epub you would use the command

zip MyBook.epub -DX0 mimetype

To add the remaining files you would use

zip MyBook.epub -rDX9 META-INF OEBPS

At this point is a good idea to validate your epub file. You can do this online at or you can download a java command line validator at

A good viewer for EPUB files is Adobe Digital Editions. It can be downloaded at​digitaleditions.