Inside the ePub Format: The OPF File

This blog post is the third in a series of posts that focus on the ePub format. In this article, I discuss the importance of the OPF file and what it contains.

In this post, I talk about the contents of an ePub file. Within every ePub file is an OPF file. OPF stands for Open Packaging Format. The OPF file is in XML format. If you do not know XML, do not worry as I will walk you through the file and you will find it is not that daunting. For a quick XML primer, visit this site.

The OPF file always contains these elements:

  • The package element is essentially a container for the elements I describe below.
  • The metadata element defines your book, like the author, publisher, copyright information, and so on.
  • The manifest element lists all the files that make up your book. Every document containing the content you wrote for the book, the navigation document (table of contents), images, audio, video, and so on.
  • The spine element defines the reading order of your content. For example, it tells an eReader to display Chapter 1 first, Chapter 2 second, and so on.

For backward compatibility to support older ePub documents, an OPF file can also contain the guide element that defines a separate table of contents file.

The following screen capture is an excerpt of the OPF file for my latest book:

Screen capture of an OPF file.

 

While it may look a little confusing at first, you can see how each area of the OPF file contains the elements you need to build the book. Let’s take a deeper look at each element. Since the package element is nothing more than a wrapper for the OPF file, I will not cover that any further.

The metadata element

As you can see in the following image, the metadata element has a <dc:title> element. Contained within that element is the title of the book.

The metadata element.

 

There are some other elements in this section as well. For example, there is a rights section where you can make any legal statements (copyrights, etc.).

Back at the top of the previous image, you will see a creator element. There must be at least one creator, and this is usually the author of the book. You can have many types of creators. In this example, there are two creators. For my sample, they have the person’s name is the same but you can see the person was responding for creating (authoring) the book and contributing to the book. You can create as many of these as you need. For example, you can have multiple authors, contributors, editors, and so on.

You might be wondering what the refines property means. Using creators-1 as an example, you can see William E Raymond is the author. There is a refines line that defines the person’s role. In this example, I am the author (represented as aut). Some systems track the first and last name in opposite order, so the there is another refines property for file-as, storing my name as Raymond, William E. Finally, there is a display-seq, and this defines the level of importance, so since I wrote the book, I get top billing. If I contributed less to the book, there would be a disp-seq of for someone else, and then I would be listed as an author with a display-seq of 2.

The manifest element

The manifest element may be the most important element to get right. You must add the files that make up your book. For example, you will add the cover image, a book cover file, a navigration document, the css file that defines the look-and-feel for your book, all the documents that make up your written words, any graphics that display within the book, and much more

The manifest element.

Understanding the manifest element is very important because if you do not get this right, then your content will not display in the book. For example, let’s say you add a very important file called important_readme.xhtml in your ePub file. If that file has no mention in the manifest element of the OPF file, that important_readme.xhtml file will never display.

While you do need every component of your book in the manifest file, you do not need to place the items in any particular order, but I recommend you do. That is because you need to build a spine element, which is next.

The spine element

The manifest element defines all the content in your book. The spine element defines what documents display and the order in which they display. As you can see in the following image, this OPF file is telling the eBook reader to display the table of contents (tocnav) first, the book’s cover second, and then all the xhtml files that make up the book. If you are wondering where the idref names came from, take another look at the manifest element and you will find every item has a id associated with them.

The spine element.

Notice in the previous image that there is a lot less information listed. This section is smaller because I am only telling the eBook reader “here are the files that make up my book.” Some of these files will display images, audio, or other media types, so that is why the manifest element captures all that information.

To summarize the spine section, think of this as being your book. It says there is a cover page, a table of contents, and some pages.

There are still plenty of eBook readers out there that do not support ePub 3.0. For this purpose, you can optionally add an ncx file. This ncx file is a separate file that attempts to create a reading order for your eBook. I cover the ncx file in a future post, but remember, you do not need one for ePub 3.0 eBook readers.

The optional guide element

You no longer need the guide element, but I recommend you consider keeping it to support older eBook readers.

As you can see in the following image, the guide element adds the table of contents to the book. In ePub 3.0, you do not need this because the manifest element already contains the table of contents file and that file has a property of nav (you can go back to the manifest element section of this post to see how that is done on the image.

The guide element.

Summary

Think of the OPF file as a recipe. A recipe usually has a name (a title), who wrote the recipe, when the recipe was written, and so on. That recipe information is in the metadata element in the OPF file.

The recipe also includes a list of all the ingredients and equipment you need. This list of ingredients and equipment is the manifest element in the OPF file.

As with most recipes, there are specific steps you take first, second, third, and so on. The order in which you display them is the spine element. If you are working with an older ePub format, the guide element performs a similar job.

As you can see, the OPF file is the heart of your eBook, tying all the components of your work together into a single package so the eBook reader will display the information you want, in the order you want it.

2016-10-21T13:42:39+00:00

3 Comments

  1. alan snedeker July 27, 2016 at 11:07 am - Reply

    Thanks….I’m almost ready to publish a book on my experiences on Madison Avenue, so your articles are timely and make sense.

    • Bill Raymond July 29, 2016 at 8:18 pm - Reply

      Glad to be of help. Please let me know if there is anything else you would like to see on the site!

  2. VSO Publishing LLC August 8, 2016 at 3:20 pm - Reply

    I am currently in the formatting process of my book, getting it into the ePub. I am not too familiar with code, but this attention to detail is very helpful. Thanks!

Leave A Comment