Skip to content

Customize book pages with CSS

Denis Evsyukov edited this page Dec 4, 2026 · 3 revisions

Customize book pages with CSS

User guide · Optional bookOrbit sync

Open the editor and try a rule

  1. Open a book on a page with ordinary text. Tap the centre to show the reader menu.
  2. Open Settings → Book formatting → Custom CSS (Настройки → Оформление книги → Свой CSS). Older versions use Settings → Book styles (Настройки → Стили книги).
  3. Paste the following text without the Markdown fences, then tap Save. The open book is laid out again around your reading position.
p {
  text-indent: 0;
  margin-bottom: 0.6em;
}

p selects paragraphs; text-indent and margin-bottom are properties; 0 and 0.6em are their values. This trades the first-line indent for a visible gap after each paragraph. Put a semicolon after each declaration. To leave yourself a note, use /* comment */.

Scope: there is one stylesheet for all books on this device, not one per book or per appearance profile. It changes the reading page, not the EPUB/FB2 file, library, menus or bookOrbit web reader. A class or ID can narrow a rule, but another book with the same markup can also match.

Keep a copy. In the editor's ⋮ menu, Export CSS saves a .css file. Import CSS replaces and applies the whole sheet, rather than appending. Use a UTF-8 file of at most 1 MiB. An unreadable file or unbalanced braces, quotes or comments leaves the active sheet unchanged. These file commands are only available in newer versions; on older versions, copy the text to a file yourself.

Undo or clear. Use Put the last version back (Вернуть прошлую версию) in the editor menu if available, or choose Restore the built-in style (Вернуть встроенный стиль). Restoring removes your CSS, not the book's formatting or your ordinary reading preferences. Export any sheet you want to keep before replacing it.

How rules match and override

A tag is part of the book's markup: <p>Text</p> has the tag p. A selector says which existing elements to style; it does not add tags to the book. Use p, not <p>, in CSS.

Selector What it matches Example
p Any element with that tag p { line-height: 1.4; }
h1, h2 Each selector in a comma-separated list h1, h2 { text-align: left; }
p.lead A p with class lead p.lead { font-size: 115%; }
#opening The element with ID opening #opening { text-indent: 0; }
blockquote p A paragraph anywhere inside a quote blockquote p { text-indent: 0; }
blockquote > p A paragraph directly inside a quote blockquote > p { margin-bottom: 0.4em; }
h2 + p The paragraph immediately after h2 at the same level h2 + p { text-indent: 0; }
h2 ~ p Later sibling paragraphs after h2 h2 ~ p { margin-top: 0.25em; }
a[href] Links with an href attribute a[href] { text-decoration: underline; }
body[name="notes"] An FB2 body whose name is exactly notes body[name="notes"] p { line-height: 1.2; }
[type~="footnote"] An element with footnote among the words of type [type~="footnote"] p { text-indent: 0; }
p:first-child A p that is the first element child of its parent p:first-child { text-indent: 0; }
p:not(.lead) A paragraph without the class lead p:not(.lead) { margin-bottom: 0.4em; }
tr:nth-child(even) A table row in an even child position within its parent tr:nth-child(even) td { font-weight: bold; }
blockquote * Elements inside a quote, not the quote itself blockquote * { font-family: "PT Serif"; }

A matching declaration in your CSS overrides the same property on that element in the book or the app's layout rules, including inline styles. You don't need !important for that. Other properties keep their previous values. Among your own rules, the more specific selector wins (p.lead over p); if equally specific, the later declaration wins. Use !important only to give one of your rules priority over another.

Inheritance is different. body { font-family: "PT Serif"; } doesn't replace a font explicitly set on p or on an em inside it. Match the elements that set it: p, p em { font-family: "PT Serif"; }. Likewise, use both blockquote and blockquote p if you want to set alignment on the block and its paragraphs. Don't start with *: it is easy to unintentionally change notes, headings and code.

Tags and examples

Use the examples individually, not as one big stylesheet. These are useful elements the engine can style, not a list of tags every book contains. EPUB normally contains XHTML; FB2 uses its own XML tags. A converted file may use only generic div, span, and p elements with classes. A stylesheet can't recreate missing structure or control text baked into an image.

Common text and tables

Tag What it is Example
body Main content container; FB2 can have more than one body { line-height: 1.35; }
p Paragraph p { text-indent: 1em; }
a Link, including note references a { text-decoration: underline; }
strong, b Strong emphasis or bold text strong, b { font-weight: bold; }
em, i Emphasis or italic text em, i { font-style: italic; }
sub, sup Subscript and superscript sub, sup { font-size: 75%; }
code Inline code, or code inside pre code { font-family: monospace; }
table Table container table { font-size: 95%; }
tr Table row tr { line-height: 1.3; }
th Header cell th { text-align: left; font-weight: bold; }
td Data cell td { padding: 0.25em; }
caption Table caption caption { text-align: left; font-style: italic; }

EPUB and HTML

Tag What it is Example
h1 Top-level heading h1 { font-size: 160%; }
h2 Second-level heading h2 { margin-top: 0.8em; }
h3 Third-level heading h3 { text-align: left; }
h4 Fourth-level heading h4 { font-size: 115%; }
h5 Fifth-level heading h5 { font-style: italic; }
h6 Sixth-level heading h6 { margin-bottom: 0.35em; }
article Self-contained part of a document article { margin-bottom: 1em; }
section A section or chapter, if the book uses it section.chapter { page-break-before: always; }
div Generic block; usually useful with a class div.notice { padding: 0.4em; }
span Generic inline segment span.foreign { font-style: italic; }
blockquote Block quotation blockquote { margin-left: 1em; margin-right: 1em; }
q Inline quotation q { font-style: italic; }
cite Citation or title of a cited work, usually inline in HTML cite { font-style: italic; }
aside Sidebar or note aside { margin-left: 0.75em; }
ul Bulleted list ul { list-style-type: disc; }
ol Numbered list ol { list-style-type: decimal; }
li List item li { margin-bottom: 0.3em; text-align: left; }
dl List of terms and descriptions dl { margin-top: 0.5em; }
dt Term dt { font-weight: bold; }
dd Description dd { margin-left: 1.2em; }
pre Block of preformatted text pre { white-space: pre-wrap; text-align: left; }
img Image img { max-width: 85%; }
figure An illustration or other self-contained figure figure { text-align: center; }
figcaption Caption for a figure figcaption { font-size: 85%; text-align: center; }
hr Thematic break or rule hr { margin-top: 1em; margin-bottom: 1em; }

The class names chapter, notice, and foreign are examples, not built-in names. Replace them with the classes in your EPUB. The <title> in an XHTML file's <head> is metadata, not the chapter heading; use h1–h6 or the element actually used in the body.

FB2

Tag What it is Example
section Chapter or nested section section > title { margin-bottom: 0.8em; }
title Visible book, section or poem heading (often contains p) section > title > p { text-align: left; text-indent: 0; }
subtitle A subheading in the text subtitle { font-style: italic; text-align: left; }
epigraph Epigraph epigraph { margin-left: 2em; }
cite Block quotation in FB2 cite p { text-indent: 0; text-align: left; }
poem An entire poem poem { margin-top: 1em; margin-bottom: 1em; }
stanza A group of verse lines stanza { margin-left: 1.5em; }
v One line of verse v { text-align: left; text-indent: 0; hyphens: none; }
text-author Attribution in a quote, poem or epigraph text-author { text-align: right; font-style: italic; }
date Date, for instance at the end of a poem poem date { text-align: right; }
empty-line Explicit blank line, not an empty paragraph empty-line { height: 0.5em; }
emphasis Emphasis emphasis { font-style: italic; }
underline Underlined text when the book uses this tag underline { text-decoration: underline; }
strikethrough Text marked as struck through strikethrough { text-decoration: line-through; }
image FB2 illustration; not the XHTML img tag section image { max-width: 85%; }
annotation Summary, if the engine presents it in the reading flow annotation p { font-style: italic; }

Metadata such as book-title and author, the embedded binary data, and the library's separately rendered cover and book details are not useful targets for page styling. A .fb2.zip containing one FB2 uses the FB2 markup; compression doesn't change its tags.

Footnotes

Style the reference in the text and the note body separately. FB2 commonly uses <a type="note"> for the reference and <body name="notes"> for the notes. An EPUB can use epub:type="noteref" and epub:type="footnote" or ARIA roles. For these EPUB semantics, crengine selectors use type (no epub: prefix) or role, as below. Some books use a different class or a plain hyperlink, so inspect the markup if nothing changes. Don't hide the reference or the note container to make it smaller.

/* The inline reference in FB2 or EPUB. */
a[type="note"], a[type~="noteref"], a[role~="doc-noteref"] {
  font-size: 80%;
  text-decoration: none;
}

/* Note paragraphs only, not all the prose and not the reference number. */
body[name="notes"] section p,
body[name="comments"] section p,
[type~="footnote"] p, [type~="endnote"] p,
[role~="doc-footnote"] p, [role~="doc-endnote"] p {
  font-size: 1urem;
  text-indent: 0;
  margin-bottom: 0.25em;
}

1urem is a crengine unit for the reader's default text size. 100% in the note paragraph would instead use its parent's size, often already reduced by the book or app. Try the built-in Footnotes as large as the text option first if size is all you need.

Properties and units

Goal Properties and values to start with
Face and weight font-family: "PT Serif", serif;, font-weight: normal; or bold, font-style: italic;. A family must already be available to the reader or supplied by the book.
Text size and spacing font-size: 110%;, line-height: 1.4;, letter-spacing: 0.04em;. A unitless line-height is a multiplier. Use small steps; more spacing means fewer words per page.
Alignment and indents text-align: left;, center, right or justify; text-indent: 0; or 1em. text-indent adjusts the first line, not the whole block.
Space around a block margin-top, margin-bottom, margin-left, margin-right outside it; padding inside it. margin: 0.5em 1em; sets top/bottom to 0.5em and left/right to 1em. Use narrow properties to avoid unintentionally resetting other sides. Use reading settings, not body margins, for the reader's outer page margins.
Colour and decoration color: #303030;, background-color: #eee4d0;, text-decoration: underline; or none. Fixed colours don't automatically become an appropriate pair for every app palette. Test them in Day and Night, or leave colours to the palette.
Borders, images and tables border-left: 2px solid #888;, max-width: 85%;, border-collapse: collapse;. Image and table layout can still be constrained by a parent box or the renderer; check narrow screens.
Wrapping and hyphenation white-space: pre-wrap; keeps whitespace but allows wrapping; hyphens: none; disables automatic hyphenation for matching elements. Automatic hyphenation also depends on the book's language and available dictionary.
Page breaks page-break-before: always; starts a matching block on a new page; auto removes that rule's forced break. page-break-after: avoid; asks to keep a heading with what follows. page-break-inside: avoid; is a request, not a way to fit an oversized block on a single page.
Hiding an element display: none; removes the matched element and its contents from layout. Start with a narrow selector for a decorative element, e.g. div.ornament { display: none; }, not headings, links, or whole sections.

Use em for lengths that scale with the local text (e.g. a paragraph gap), % for a relative size (font-size uses the parent's size), and 0 for no length. rem follows the book's root font size; an EPUB can set it separately for a chapter. CSS px is a CSS length, not the same as Perigee's Android font-size control in dp.

Pseudo-elements and conditional rules

/* An actual first letter or line, if the element has visible text. */
p.lead::first-letter { font-size: 145%; font-weight: bold; }
p.lead::first-line { font-style: italic; }

/* Generated text, for books with an explicit matching class. */
p.label::before { content: "[ "; }
p.label::after { content: " ]"; }

::first-letter and ::first-line accept a restricted set of properties. ::before and ::after can add visible text; they don't edit the book. @media and @supports work for features that crengine recognizes:

@media all {
  p { line-height: 1.35; }
}
@supports (display: block) {
  pre { white-space: pre-wrap; }
}

These examples are parsed by crengine, not Chrome. Don't rely on browser Grid/Flexbox, JavaScript, transitions, CSS custom properties (--name / var()), web-font downloads or selecting the app's Day/Night setting via prefers-color-scheme. Use the app settings for UI, themes and page margins.

Copy-and-paste recipes

Left-aligned prose, separated paragraphs, compact notes

p {
  text-align: left;
  line-height: 1.4;
  text-indent: 0;
  margin-bottom: 0.55em;
}
body[name="notes"] p, body[name="comments"] p,
[type~="footnote"] p, [role~="doc-footnote"] p {
  line-height: 1.2;
  margin-bottom: 0;
}

The second rule stops the general paragraph spacing from making these notes taller. To keep indent instead of a gap, use text-indent: 1em; margin-bottom: 0; in the first rule.

Larger headings, without forcing another FB2 chapter break

h1, h2 {
  font-size: 145%;
  text-align: left;
  page-break-after: avoid;
}
body:not([name="notes"]):not([name="comments"]) section > title {
  font-size: 145%;
  page-break-before: auto;
  page-break-after: avoid;
}
body:not([name="notes"]):not([name="comments"]) section > title > p {
  text-indent: 0;
  text-align: left;
}

The FB2 selectors leave the common note bodies alone. Remove page-break-before: auto if you want to preserve built-in chapter breaks. An EPUB may still start each of its separate chapter files on a new page.

Left-align verse and make code easier to fit

stanza { margin-left: 1em; }
v { text-align: left; text-indent: 0; hyphens: none; }
pre { text-align: left; white-space: pre-wrap; }
pre, pre code { font-family: monospace; }
pre { font-size: 90%; }

The verse rules are for FB2. EPUB poems often use custom classes; for example, div.poem p works only if the book uses that structure. For centred verse instead, try v { text-align: center; text-align-last: center; text-indent: 0; }.

Use a different already available face for headings

@font-face {
  font-family: "My heading face";
  src: local("PT Serif");
}
h1, h2, section > title > p { font-family: "My heading face", serif; }

local() names a family the app can already use. It does not install a font. Import or download a face using the reader's font controls first, then use the family's name (not the .ttf filename). For a simple font change, font-family: "PT Serif", serif; works without an alias. Update Perigee if an alias behaves differently when reopening the book than when saving the CSS on an older version.

If a rule has no effect

  1. Check Save. The editor checks balanced braces, quotes and comments, not full CSS validity. An unsupported property, unsupported value or unmatched selector can be silently ignored after saving.
  2. Make the test visible and narrow. On an ordinary paragraph try p { text-align: center; text-indent: 0; } first. On a heading try h2 { font-size: 160%; } in EPUB or title p { text-align: left; } in FB2. If the first test works but the second doesn't, the book may use another tag.
  3. Find the markup. Work on a copy: unzip an EPUB and inspect its .xhtml or .html chapter files in a text editor; inspect an FB2 as XML (unzip it first if necessary). Search for a distinctive phrase near the text you want to style. For <p class="first">…</p> try p.first; for <div id="opening">…</div> try #opening. Perigee may normalize imported formats into different markup. If you can't inspect the source, start with simple p, h1, h2 or title p rules and check a known page.
  4. Check the child and your other rules. A rule on the container won't replace a value set on its child. If two of your rules set the same property on the same element, temporarily keep only the one you're testing. Adding !important can't make an unsupported property or a non-matching selector work.
  5. Restore if needed. Recover the previous version, import your saved sheet or restore the built-in style. Check ordinary text, headings, notes, tables and images in more than one book before keeping a global stylesheet.

For the implementation, see the reader's CSS rules, precedence and limitations and the pinned crengine submodule (cr3gui/data/fb2.css, epub.css, html5.css for default styles; crengine/src/lvstsheet.cpp for the parser). The format styles are the best starting point for additional selectors, not a guarantee that a specific book uses them.