Cascading stylesheets (CSS)

Structure and functionality of cascading stylesheets for EPUB and web pages

There are two cascading stylesheet (CSS) files located in the directory /stylesheets: epub.css for an EPUB ebook, and web.css for web pages. These allow you to specify a range of text, graphic and table styles for HTML pages. The CSS elements are arranged in each CSS file to match up with the order of book components and features for PDF ebooks as outlined in the XSLT stylesheets. The order of features in the EPUB and web CSS files is:

XML markup to edit

No XML markup is needed to set up or change CSS features in epub.css or web.css files.

Stylesheet settings to edit

Next to most features in the EPUB and web CSS files is a feature ID number, which corresponds to the relevant PDF stylesheet feature. For example, the CSS feature below sets the top margin for the book title on the title page:
.book .titlepage h1.title {
    margin-top: 40px; /*p3-120*/
In a comment next to the margin-top attribute, it has the equivalent stylesheet feature ID of p3-120, which sets the vertical space before the book title in a PDF ebook.

Use the stylesheet feature ID to cross-reference a CSS feature back to the equivalent feature in a PDF ebook. You will find the ID number in the relevant PDF stylesheets (in the directory /xml/stylesheets/pdf_stylesheets). This cross-referencing back to a PDF feature helps you to understand what text or graphics that each CSS selector statement affects in EPUB ebooks and web pages.