While you can create and package an ePub manually, Sigil is a simple but powerful ePub editor that will save you time. It can open your (X)HTML file and help you turn it into a valid ePub, or let you revise an existing ePub.
Download links
Edit Preferences
After installing Sigil, take a moment to edit Preferences. The defaults are usually fine, but under Clean Source, I prefer to use Pretty Print instead of HTML Tidy because it doesn’t unexpectedly rewrite your code. In any case, error detection does occur when you switch from one file to another or save your file, unless you explicitly turn it off. Leave it on to painlessly validate code as you progress through your files. When an error is reported, choose to fix it manually (vs. automatically) to control results.
Sigil lets you work in Code view or Book View (WYSIWYG). Nevertheless, the appearance of your book in Sigil is an approximation of how it will look when viewed using an ePub reader. The default “Book View” font in Sigil is Arial, though you can change it to a serif font if you want it to look more like a generic eReader.
Be aware that the amount of work required to produce a valid ePub that pleases you or your client depends on the complexity of your formatting, special requirements, or number of illustrations. The purpose of this Step is to pass along a few tips from my own experience, not to cover everything in the Sigil documentation.
Import your XHTML or HTML file into Sigil
Open your html, xhtml, or ePub file in Sigil. Remember that you cannot open a Word document in Sigil, but it will be fine with Word’s filtered HTML output.
This dedicated ePub editor will create several necessary folders and files that are accessible in the Sigil interface and a few standard files and folders that are part of the ePub structure (see below), but don’t need editing and are not viewable or editable. To construct a basic ePub, you will work mostly with the following:
- Text folder for your xhtml files
- Styles folder for your CSS files
- Images folder for your cover and interior images
- content.opf – required metadata file that describes your book. Edit indirectly by selecting Tools in top menu, then Metadata Editor (F8). You may also edit content.opf directly if you wish.
- toc.ncx – required logical table of contents that becomes the navigation panel in ePub documents. For more control over the toc.ncx, you can generate a fresh copy at any time using the Tools / Table of Contents menu. You can manually add, delete, or edit entries in the toc.ncx by selecting Tools, then Table of Contents / Edit Table of Contents.
ePub Structure
An ePub is a special zipped package. If you copy your .ePub file and change the extension to .zip, you’ll see something like this when you view the contents:
- META-INF
- container.xml
- OEPBS
- Text
- Styles
- Images
- content.opf
- toc.ncx
- mimetype
If you break open an ePub and then want to reverse the process, be careful. The files must be added to the zipped package in a certain order in order for the ePub to validate. You can control the process using Windows OR the Zip7 program. The easiest method is to use Windows to create a compressed (zipped) folder. Then drag the mimetype file into the empty folder, followed by the META-INF and OEPBS folders. Then rename the file with a .epub extension and validate with epubcheck.
The Text Folder
Your book’s content files are in the Text folder. By default, your imported file will be named Section0001.xhtml. Added files will be named sequentially, as Section 0002.xhtml, Section0003.xhtml, and so on. You may rename any file to whatever you want. You may also reorder files by dragging them to a new position. The order of files in the Book Browser, not the title, determines the order in the ePub.
At the top of each document file in the Text folder, there is an XML declaration that specifies the encoding and the XHTML 1.1 DTD and namespace:
<?xml version="1.0" encoding="utf-8" standalone="no">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
I recommend using UTF-8 because it’s standard for web documents and you can simply type many special characters using an Alt-key combination rather than cumbersome HTML entities. However, if you didn’t tell Word (Options / Advanced / Web Options) to save HTML documents encoded as UTF-8, it might be ISO-8859-1 (Latin-1). That will also work. However, if you see charset="windows-1252"
in your Word-to-HTML conversion, that’s a problem that needs to be fixed by changing Word Options.
Style Sheets
Of course you can create an ePub without paying attention to styles, but it will look much better and more consistent across eReaders if you at least create paragraph styles. Sigil will honor your existing internal style sheet — the one that you edited in Step 3. It will also add new styles prefaced with “sgc” to an internal style sheet if your book file contains inline styles. If you use HTML Tidy to Clean Source, Sigil will create new CSS classes for paragraphs that are entirely bold or italic.
My advice is to review your imported file and take the time to examine these “sgc” CSS styles. You may find that you can incorporate some of the generated styles into existing ones. It’s good that Sigil behaves this way, even if it seems inconvenient, because inline styles are deprecated in XHTML 1.1 and are harder to maintain.
For example, let’s say you have a paragraph that’s marked up like this and you are using HTML Tidy for Clean Source:
<p><i>Ridiculus mus turpis sit tincidunt, et cursus in quis ut aenean nunc, ut aliquet enim nisi quis dolor! Nec tincidunt. Ridiculus adipiscing nunc nisi diam nec, egestas et odio turpis, sit lorem.</i></p>
When the file is saved, Sigil will add a new class — p.sgc-1 {font-style: italic;} — to an existing or new internal style sheet and assign the class to the paragraph:
<p class="sgc-1">Ridiculus mus turpis sit tincidunt, et cursus in quis ut aenean nunc, ut aliquet enim nisi quis dolor! Nec tincidunt. Ridiculus adipiscing nunc nisi diam nec, egestas et odio turpis, sit lorem.</p>
If you already have a declaration in your CSS file for italic text, it makes sense to assign your existing class to such paragraphs instead of adding a new “sgc” class. The same logic applies if there are a lot of other inline styles pulled into an internal style sheet. Consolidate styles to keep your style sheet organized and small. Sigil’s Find and Replace option can help you do this very quickly and you’ll only have to do it once, when you first start working on your book file.
When you’re satisfied with your internal stylesheet and have reviewed any Sigil-added styles, add a new blank CSS file in the Styles folder and move your internal stylesheet into it. That is, copy and paste the contents into the CSS file without including the <style></style> tags. Then delete the internal stylesheet and add a link to the external stylesheet within the <head> tag of your book file:
<link href="../Styles/Style0001.css" rel="stylesheet" type="text/css" />
As you edit the book’s content files, make any needed revisions to the new external style sheet. Handling styles this way is a good habit because it prevents repetition of an internal stylesheet in each new book file as you split the book into separate files at chapter breaks.
If you plan to generate a .mobi file for Kindle from your ePub, keep in mind that Kindle does not understand multiple classes assigned to HTML elements, nor can you always trust the CASCADE part of CSS to work with it. For this reason, I make the CSS a bit redundant or create more specific classes than I would otherwise. I also create two ePubs, one for B&N and other ePub outlets, and one for use with Kindlegen. You don’t have to do this, but I find it a less error-prone workflow than working with one file.
Metadata
The “content.opf” file contains metadata that describes your book. In Sigil, press F8 or click Edit in the top menu bar, then click Meta to add or delete information in the content.opf file. Enter your book title, author name (last, first) and select your language. The default language is English. Click Add Basic button to add Rights metadata. You can change the Date’s “File As” property from “modification” to “publication.” If you want to keep the modification date, use Add Basic to add an entry for publication date.
Sigil translates the basic entries in the Meta Editor to this text in your content.opf:
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:identifier id="BookId" opf:scheme="UUID">urn:uuid:0268d15d-94a9-42fa-8fda-dc0c5ac08628</dc:identifier> <dc:title>City of Lost Books</dc:title> <dc:creator opf:role="aut">Smith, John</dc:creator> <dc:language>en</dc:language> <dc:date opf:event="publication">2013-07-26</dc:date> <dc:rights>Copyright 2013 by John Smith. All Rights Reserved.</dc:rights> <meta content="0.7.2" name="Sigil version" /> </metadata>
Splitting Files
Split your manuscript into separate files at page breaks. There are two ways to split files: Split at Markers and Split at Cursor. To speed things up, you can use Find and Replace to add Split Markers before every chapter header tag (h1 or h2). For example:
Find <h2>
Replace: <hr class="sigil_split_marker" /><h2>
Then select Edit/Split at Markers or press F6. Add additional required splits in the front or back matter manually. Alternatively, you can split the files manually by simply positioning the cursor where you want the break. Then click the Split at Cursor icon or press Ctrl-Enter.
Separate files are the only way to be certain that a new section starts on a new page in an ePub. Separate files are also the easiest way to avoid a bug in Kindle Fire that removes margins and padding above headers after a page break.
When you split a file, Sigil copies over the title tag and stylesheet link. When you create a new file, it does not. Save time and split your files at page breaks instead of creating new files.
If you do get into a situation where you have a lot of files that lack a stylesheet link, you can still add them all at once. Here’s how: Select files that need the meta stylesheet link, right-click and select Link Stylesheets. Check the ones to include and click OK. Done.
In the past, we used a proprietary <pagebreak/> tag or a CSS .pagebreak class — .pagebreak {page-break-before:always;} — in files for Kindlegen conversion. This method still works, but it’s advisable to abandon that practice and split your manuscript into separate files to avoid losing margins and padding above headers on Kindle Fire devices.
Paragraph styles are essential
Sigil adds space between paragraphs and no first-line indents. Don’t assume that eReaders have the same default paragraph styling. They don’t. For consistency across devices and eReaders, create CSS declarations for paragraphs even if you don’t want to style anything else.
If you include a stylesheet that specifies paragraph margins and text-indents, Sigil will dutifully display them as intended. ePub readers have their own default fonts and paragraph formatting. If you don’t explicitly add paragraph spacing, margins, and text-indent, the appearance of your book will be determined by each device or eReader used to view it.
Fiction looks more familiar with paragraph first-line indents (text-indent) and little or no space between paragraphs. For example:
p {text-indent: 5%; margin: 0; padding: 0;}
Non-fiction or technical books may look more professional with no text-indent and a blank line between paragraphs (block-style). For example:
p {text-indent: 0; margin: 1em 0; padding: 0;}
The main thing is to pick a style and stick to it throughout your book. In real life, the front and back matter may use block paragraphs even when the narrative uses first-line indents and no blank lines. Some novelists will still want text-indents plus a blank line between paragraphs or block paragraphs, even though those styles are uncommon for fiction and you’ve discussed paragraph styles. The sky will not fall and it’s their decision.
Make corrections with Find and Replace
Sigil’s Find and Replace feature will help you make repetitive corrections quickly. You can search the current file, selected files, or all files, down or up, normal, case-sensitive, or regex (regular expressions). The simple “Count all” option can be useful for seeing how many instances there are of a particular word or phrase. Read the Documentation
Add your Cover
Unlike Kindle books, ePubs need both a cover image and an XHTML cover page that references it. Upload a copy of the image that is the right dimensions and file-size for your ePub vendor. If you’re not sure what size to make the cover, 600 by 900 pixels is still a “universal” size that’s usable by most eReaders. In the past, 600 by 800 pixels was considered optimal, but newer eReaders tend to be taller and narrower than their predecessors.
Remember that Amazon’s Kindlegen requires but will discard your inside cover. Kindlegen will use your ginormous product catalog cover to derive cover images for various Kindle devices. Therefore, I think it’s now okay to use a 600 x 900 pixel image for the Kindle inside cover as well as a generic ePub cover for Barnes & Noble or Kobo. For an iBook version, use a 768 x1024 pixel image.
The cover image should fill small screens without being cropped. To achieve that, give the cover image an id or class and add a style to your style sheet that encourages auto-resizing on small screens and makes Adobe Digital Editions create a proportional thumbnail. If your image has an id of “coverimg,” the CSS declaration would look like this:
#coverimg {max-width: 100%;}
Validation
Validate your ePub within Sigil by clicking the green checkmark (or press F7), which calls the FlightCrew validator. Before publishing, run the separate epubcheck program as well. You can run epubcheck using the command-line script after installing Python on your PC. If that’s too alien, download the Pagina ePub Checker, which is a simple executable file that doesn’t require any other installation and has a nice GUI.
Remember to make desired changes to the content.opf and toc.ncx files before validating and saving your final ePub. That is, you may want to add or delete sections in the toc.ncx to control what shows up in the ePub navigation panel.
HTML Table of Contents
Kindle requires an HTML Table of Contents in addition to the NCX file. While standard ePubs use the NCX file for the navigation panel, Kindle devices use the HTML TOC as the main navigation tool and the NCX file to generate the progress bar and “Go to” specific locations. I like to include an HTML table of contents for ePubs as well as Kindle books. Use Sigil’s menu option to create the TOC from your headers to save time.
Sigil can make one for you in a few seconds based on your header tags. To do this, select Tools from the top menu, then Table of Contents / Create HTML Table of Contents. You can then edit and style the HTML TOC as you wish. If you make changes to your book that affect the order of sections, their links or titles, make sure you edit both the xhtml toc and toc.ncx files.
Review your book
At this point, you’ve completed an ePub version of your book and have successfully gone from XHTML to ePub, the world’s standard format for eBooks. You’re not done yet.
Before publishing to various outlets, take the time to review your book in Adobe Digital Editions, which may be conveniently installed on your PC. The ADE eReader is a good generic program for finding and fixing basic problems with styles or layout. If something is incorrectly displayed in ADE, it may have the same problem in another eReader. It’s an easy, fast way to do a quick quality check of the ePub file. I recommend using it.
Once your book displays well in ADE, review it on all your devices and eReaders. Amazon’s Kindle Previewer includes the Kindlegen conversion program, which accepts HTML and ePub files. If you have a book cover page, you must make a change in the content.opf file before using Kindlegen. In the <spine> section, find the reference to your cover page file and add the linear property set to “no”:
<spine>
<itemref idref="cover.xhtml" linear="no" />
It’s obviously a plot!
Each eReader has legacy default styles and behaviors, and sometimes, unexpected problems. Review and test your book thoroughly before publication to avoid time-consuming re-submissions later. If you have complex formatting, chances are you’ll need to make a new copy of your .epub file with one or more stylesheets that are customized for old (Mobi) Kindles and new Kindles (KF-8, Kindle Fire). I think it’s easier, or at least more gratifying, to start with a standard ePub file and tweak a copy for Kindle. If you self-publish to iTunes for iBookstore and include a custom sample, make two copies of the ePub and include a 768 x 1024 pixel cover in each one. You’ll need to tweak the toc.ncx file in the custom sample file so that all the links work, but that’s another story.