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:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Your Book Title</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<!-- Your book goes here -->
</body>
</html>
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):
<h2 id="ch2">Chapter Two</h2>
<div class="center"><br><img src="images/ornament.png" width="75" alt="----------"></div>
<h3>Subtitle</h3>
<blockquote>
<p>Some quote</p>
</blockquote>
<p>Lorem ipsum dolor sit amet, consectetur ... </p>
<p>Lorem ipsum dolor sit amet, consectetur ... </p>
<p>Lorem ipsum dolor sit amet, consectetur ... </p>
<p>Lorem ipsum dolor sit amet, consectetur ... </p>
<div class="center">* * *</div>
<p>Lorem ipsum dolor sit amet, consectetur ... </p>
<p>Lorem ipsum dolor sit amet, consectetur ... </p>
<p>Lorem ipsum dolor sit amet, consectetur ... </p>
<div class="pagebreak"></div>
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.
p { margin-top: 1em; text-indent: 0em; }
h1 {margin-top: 1em}
h2 {margin: 2em 0 1em; text-align: center; font-size: 2.5em;}
h3 {margin: 0 0 2em; font-weight: normal; text-align:center; font-size: 1.5em; font-style: italic;}
.center { text-align: center; }
.pagebreak { page-break-before: always; }
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:
<div id="toc">
<h2>
Table of Contents <br />
<img src="images/ornament.png" width="75" alt="----------" />
</h2>
<ul>
<li><a href="#over">Overture</a></li>
<li><a href="#pro">Prologue</a></li>
<li><a href="#ch1">Chapter 1</a></li>
<li><a href="#ch2">Chapter 2</a></li>
<li><a href="#ch3">Chapter 3</a></li>
<li><a href="#ch4">Chapter 4</a></li>
<li><a href="#ch5">Chapter 5</a></li>
<li><a href="#ch6">Chapter 6</a></li>
<li><a href="#ch7">Chapter 7</a></li>
<li><a href="#ch8">Chapter 8</a></li>
<li><a href="#epi">Epilogue</a></li>
</ul>
</div>
<div class="pagebreak"></div>
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:
<?xml version="1.0"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
<head>
</head>
<docTitle>
<text>Book title</text>
</docTitle>
<navMap>
<navPoint id="toc" playOrder="1">
<navLabel>
<text>
Table of Contents
</text>
</navLabel>
<content src="index.html#toc" />
</navPoint>
<navPoint id="over" playOrder="2">
<navLabel>
<text>
Overture
</text>
</navLabel>
<content src="index.html#over" />
</navPoint>
<navPoint id="pro" playOrder="3">
<navLabel>
<text>
Prologue
</text>
</navLabel>
<content src="index.html#pro" />
</navPoint>
<navPoint id="ch1" playOrder="4">
<navLabel>
<text>
Chapter 1
</text>
</navLabel>
<content src="index.html#ch1" />
</navPoint>
<navPoint id="ch2" playOrder="5">
<navLabel>
<text>
Chapter 2
</text>
</navLabel>
<content src="index.html#ch2" />
</navPoint>
...
</navMap>
</ncx>
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:
<?xml version="1.0" encoding="iso-8859-1"?>
<package unique-identifier="uid" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:asd="http://www.idpf.org/asdfaf">
<metadata>
<dc-metadata xmlns:dc="http://purl.org/metadata/dublin_core" xmlns:oebpackage="http://openebook.org/namespaces/oeb-package/1.0/">
<dc:Title>Book title</dc:Title>
<dc:Language>en</dc:Language>
<dc:Creator>Author name</dc:Creator>
<dc:Copyrights>Copyright owner</dc:Copyrights>
<dc:Publisher>Publisher</dc:Publisher>
<x-metadata>
<EmbeddedCover>images/cover.jpg</EmbeddedCover>
</x-metadata>
</dc-metadata>
</metadata>
<manifest>
<item id="content" media-type="text/x-oeb1-document" href="index.html#toc"></item>
<item id="ncx" media-type="application/x-dtbncx+xml" href="toc.ncx"/>
<item id="text" media-type="text/x-oeb1-document" href="index.html#over"></item>
<item id="Images" media-type="text/x-oeb1-document" href="Images.html"></item>
<item id="background" media-type="text/x-oeb1-document" href="background.html"></item>
</manifest>
<spine toc="ncx">
<itemref idref="content"/>
<itemref idref="text"/>
<itemref idref="Images"/>
<itemref idref="background"/>
</spine>
<guide>
<reference type="toc" title="Table of Contents" href="toc.html"/>
<reference type="text" title="Book" href="index.html"/>
</guide>
</package>
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!
Fabulous, what a web site it is! This web site presents useful information to us,
keep it up.
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.
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.
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.
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.
I’m not sure about that. According to the KindleGen webpage: “KindleGen generates a single file with a Mobi extension which supports both Mobi and KF8 format.”
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?
I have not encountered that issue, but then again I seldom justify text. What I can recommend is to to open to open the document in a web browser, and if it’s justified, then it’s probably a device issue.
This is wonderful and lucid and clear, Alicia. Does it also work for an Arabic (right-to-left) ebook?
In theory, yes (although I’ve never done it myself), since it’s mostly HTML and CSS, you would do it as any Arabic webpage in HTML. The problem is that Kindle doesn’t support Arabic, so I you’d have to embed your Arabic font, and if it works, it will only work on Kindle Fire HD, and Paperwhite, and you wouldn’t be able to distribute it via Amazon.
You may want to look into creating an EPUB, instead.
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.
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!!