How to Make a Kindle eBook from Scratch

Update (Sept. 11, 2015): The character set for Kindle eBooks is now UTF-8. And recommends using the UTF-8 character over entities (© over ©).

There are many ways to create a Kindle eBook, but creating your own source files, and then using KindleGen to convert it into Kindle Format 8 will give you more control over the end result, than relying on a plugin.

If you are a web designer, like me, you already know the technologies you need to make Kindle eBooks from scratch: HTML, XML and CSS. All you need to know is how to put those technologies together, and you’ll be in business.

What you’ll need

  • Text editor: most text editors will do for this task, but I’ve had editors crash on me when editing really long books (hundreds of pages long). I usually prefer doing my eBook editing in BBEdit, but TextWrangler may work just as well for your needs.
  • From the Kindle Publishing Program page:
    • Amazon Kindle Publishing Guidelines: this PDF outlines their standards.
    • KindleGen: a command line program to convert the source files into Kindle Format 8.
    • Kindle Previewer: a simulator, so you can test your eBook.
    • Sample Books: I strongly recommend that you look at the samples. Some have examples of how to add images, text, media, etc.

This tutorial will cover the basics of making a simple eBook, but its just a matter of studying the publishing guidelines, and sample books to be able to make more complex eBooks.

File structure

To create an Kindle eBook, you need the following files:

  • The book in HTML format (it can be all in one file, or you can break it up, a chapter per file, for example)
  • An OPF (Open Packaging Format) with the book’s details
  • An NCX (Navigation Center eXtended) table of contents
  • Cover image (JPEG or TIFF)
  • Any other assets your book may have (CSS files, images, fonts, etc.)

If you download the sample books, you can see how their files are organized.

Formatting the book: HTML

This can be time consuming, but all you need to do is convert the book into a web page. You can use XHTML, or HTML5, but have to be careful to set the encoding as ‘Latin-1’ (ISO-8859-1) UTF-8 (see the update at the beginning of this article). Here’s a template of what your HTML file may look like:

You can export from inDesign (or Word, ugh!) into HTML. If you are like me,  though, you’ll cringe at the sight of the generated code, and you’ll want to clean it. I strongly recommend familiarizing yourself with Grep for that.

When structuring your book with HTML, keep things simple and structural. Use HTML to set up your headings, paragraphs, blockquotes, lists, strong or emphasized text, etc. You can see a full list of available tags on page 71 of the guidelines.

Here’s an abridged version of what the HTML for a book chapter may look like (notice the id in the chapter title, and the pagebreak class at the end, I’ll explain what that’s about soon):

As you can see, you can add divs with classes, and even images (check out the publishing guidelines for the details). Just remember that you have no control over the size of the device an the base font the reader is using.  Think responsive!

Formatting the book: CSS

Unless you are doing a graphic heavy book, children’s book, or comic book, your CSS will be very simple. Remember that Kindle users are able to set the size and font they want to use, so you shouldn’t fiddle with that too much.

Notice how margins, paddings, and font sizes are in ems. This way, the spacings will be relative to the font size chosen by the reader.

If you want to create page breaks, you can use CSS: page-break-before or page-break-after. Alternatively, you can use Kindle’s custom tag: <mbp:pagebreak />. I usually put one at the end of each chapter.

Check out the publishing guidelines for a list of supported CSS (page 75).

 Table of contents: HTML

At the beginning of the book, you need to have a Table of Contents (TOC). This is simply a list of links to the different chapters or sections of your book. That’s why you need to put ids to each chapter or section heading.

I personally prefer having my HTML TOC in a list. Something like this:

If you divided the HTML into multiple files, make sure they point to the file, and id. For example: <a href="chapter2.html#ch2">Chapter 2</a>.

Table of contents: NCX

In addition to having a table of contents in your HTML, you need to have an XML file with the same information. This XML file allows for better user experience, since it lets readers navigate the book better.

If you downloaded the sample books, you can see the ones included with them, but here’s an excerpt of the NCX TOC version of the HTML TOC from above:

It may look intimidating, but if you notice it’s just a list of navPoint nodes. Each node has the information of the name of the chapter, the location (src), and the playOrder (this is a sequential order in which each chapter appears).

I recommend simply using one of the NCX files in the sample books, and modifying it to match your book. Just be careful to keep the links accurate, and the playOrder, well, in order.

The Book Details: OPF

The OPF is an XML file that has all of your book’s details, from ISBN, title, author, book cover,  to the list of all the files included in the package.

As with the NCX, I recommend using one of the sample book’s OPF as a template:

Some of the OPF files in the book samples have comments with explanations, but the one above should give you an idea of the information it contains:

  • Metadata: Information such as book title, author, publisher and cover art. There is a list of all the metadata you can include in the OPF website.
  • Manifest: The list of all the files included in the package (HTML, and NCX). I recommend that you list all CSS and image files as well. If you do, when generating the Kindle book, any missing (or misspelled) files will generate a warning.
  • Spine: The list of HTML files, in the order in which they must be read.
  • Guide: This element points to key items in your book, such as the TOC, where the text starts, if there is a dedication, etc.

Cover Image

As you can see in the OPF, you need to include information about the cover image. The image should be:

  • JPEG or TIFF
  • 1.6 ratio preferred
  • Minimum: 625 pixels on the shortest side and 1000 pixels on the longest side
  • Best: 1563 pixels on the shortest side and 2500 pixels on the longest side

Creating the Kindle eBook

Now that you have all the necessary files, you are ready to create the Mobi. Here’s where KindleGen comes in.

After you downloand KindleGen for your platform, you need to run it in the command line. The KindleGen download includes instructions, but the command would look something like this:

/Applications/kindlegen /Users/me/Documents/Book/book.opf 

If you are in a Mac, the easiest way is to drag KindleGen into the Terminal, then drag the OPF, and click enter. KindleGen will start running, and if everything is fine, a Mobi file will be generated in the same folder where the OPF is located.

Some of the errors you may encounter may have to do with broken links in the TOC (usually typos in the ids or links), and missing files (typos in file names).

Your masterpiece is done!

Once you have the Mobi, you can open it in Kindle Preview,  any other eBook reader, or even an actual Kindle device.

If you are happy with the results, you are ready to upload it to the Kindle Store!

12 Responses to “How to Make a Kindle eBook from Scratch”

  1. delete google plus android

    Fabulous, what a web site it is! This web site presents useful information to us,
    keep it up.

  2. tomozawa

    I created web pages using Notepad and
    now I want to convert these HTML pages into
    an e-book.
    I spent some time looking for information.
    Alicia’s this site is the best for me.
    So I presume I don’t need either WinZip or Epub
    as long as I have my HTML files and
    cling to Kindle Direct Publishing.
    Keep your good work up.

    • Alicia Ramirez

      That’s right. You don’t need to WinZip or EPUB, all you need is KindleGen. It doesn’t even require that you have all the XML files I described in the tutorial, just the HTML, but you’ll get better results if you take the time to create them.

      If you want to also submit your book to Apple’s iBookstore, then you will need to create an EPUB, though. The method I described is for Amazon only.

      • tomozawa

        Thanks Alicia,
        I have successfully uploaded my HTML files
        and eBook cover to Kindle.
        Living in Japan,the Cover Creator is not available at present.
        So I logged in the kindle site on the stateside.

        Thanks again for your tip about Apple’s iBookstore.

  3. The Hand That Rocks the Cradle

    Thank you so much for this helpful blog article. It really helps so much! However, with that said, I guess I’m getting confused. there was talk on the Kindle forums that Kindle no longer accepts Mobi and that it’s obsolete formatting. I don’t know what to believe.

  4. Thomas White

    Can you suggest about listing justify ul and ol. If we are previewing listing on Kindle Fire HDX 8.9 device not showing justify. It might be device’s issue or coding?

  5. Mohamed

    This is wonderful and lucid and clear, Alicia. Does it also work for an Arabic (right-to-left) ebook?

  6. barcelona

    Hello I am so happy I found your website, I really found you by mistake,
    while I was researching on Bing for something else, Regardless I am here now and would just like to say thanks for a fantastic post and a all round thrilling
    blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have bookmarked it and also added in your RSS feeds, so when I have time I will be
    back to read more, Please do keep up the great b.

  7. Suzanne T. Smith

    Just what I need to finish up my eBook, Good Food for Great Dogs: Busting the Dog Food Myths–Secrets of Canine Nutrition. I write in WordPerfect, and most books on Kindle formatting start with Word (ditto the “UGH!”), so this post is perfect. Thank you!!