Introduction
FictionBook is an XML ebook format created in Russia in the early 2000s and widely
used in Russian-speaking countries. A book is a single XML file that describes its
structure, such as sections, titles, poems and epigraphs, rather than its appearance,
leaving the layout to the reading program. Files are often distributed compressed as
.fb2.zip.
Structure
An FB2 file is XML with the root element
FictionBook in the namespace
http://www.gribuser.ru/xml/fictionbook/2.0, the namespace of every published schema (2.0, 2.1, 2.2 and the repository’s later one);
calibre also reads a root in http://www.gribuser.ru/xml/fictionbook/2.1, see
Divergence from spec. Optional stylesheet elements come first. The
description element holds
the title, authors, genres, language, and
details of the electronic document and the printed edition; one
body holds the text as nested
section elements with titles, paragraphs, poems and tables, and a
second may hold the notes; and binary
elements hold the cover and other images, encoded in Base64 and referred to by
their ID through XLink.
<?xml version="1.0" encoding="UTF-8"?>
<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0"
xmlns:l="http://www.w3.org/1999/xlink">
<description>
<title-info>
<genre>short_story</genre>
<author><first-name>Anna</first-name><last-name>Smith</last-name></author>
<book-title>A Short Story</book-title>
<lang>en</lang>
</title-info>
<document-info>
<author><nickname>scanner</nickname></author>
<date value="2026-11-12">12 November 2026</date>
<id>a1b2c3d4-0001</id>
<version>1.0</version>
</document-info>
</description>
<body>
<section>
<title><p>Chapter 1</p></title>
<p>It began on a Tuesday.</p>
</section>
</body>
</FictionBook>
Divergence from spec
The specification here is the schema (the author’s published FictionBook.xsd files, see the
versions) and the author’s description on fictionbook.org. Eight programs’ source or data was read for what they do: the current FBReader for Android (geometer/FBReaderJ: fb2/FB2NativePlugin.java and FB2AnnotationReader.java), Okular
(KDE/okular: generators/fictionbook/converter.cpp), MuPDF (ArtifexSoftware/mupdf: source/html/html-doc.c and html-parse.c), the legacy FBReader in C++
(geometer/FBReader on GitHub: fbreader/src/formats/fb2/FB2Reader.cpp and FB2BookReader.cpp), calibre
(kovidgoyal/calibre: ebooks/conversion/plugins/fb2_input.py, ebooks/metadata/fb2.py,
ebooks/fb2/fb2ml.py and resources/templates/fb2.xsl), the crengine used by KOReader
(koreader/crengine: cr3gui/data/fb2.css), Foliate (johnfactotum/foliate-js: fb2.js) and the schema that
FictionBook Editor ships (evpobr/fictionbookeditor: FBE/FictionBook.xsd). Where they differ from the schema, the explorer supports both when they do not clash.
| Where | Spec says | Programs do |
|---|---|---|
| Namespace | Every published schema has the target namespace http://www.gribuser.ru/xml/fictionbook/2.0. | calibre’s input plugin accepts a root in that namespace or in http://www.gribuser.ru/xml/fictionbook/2.1 (FB2NS, FB21NS) and converts both the same way; any other namespace is treated as 2.0. The explorer accepts both. |
style attribute | xs:string on p, v, subtitle, td, th, table; the description speaks of styles for paragraphs. | calibre copies the value into the HTML style attribute, that is, reads it as CSS declarations (fb2.xsl, templates for fb:p and fb:td). The explorer reads a value with a colon as declarations and any other value as a rule name. |
stylesheet, style element | The description recommends one text/css stylesheet; the style element’s name names a style. | calibre parses every text/css stylesheet and writes each style element as a span whose class is its name, so the CSS rules apply. The legacy FBReader’s tag table has no stylesheet or style entry: the element is ignored (the text inside a paragraph still shows). The wiki’s page for the element (2005) says the author knew of no software that supported it. The explorer applies a subset (not described, below). |
| Tables | table, tr (align), th and td (id, style, colspan, rowspan, align, valign). | calibre writes table, tr (with align), td/th (with align, style, colspan, rowspan) and drops valign. The legacy FBReader’s tag table has no table element, and its character-data handler adds text only while a paragraph is open, so by that code the text of cells is not shown. Foliate’s fb2.js turns th/td into HTML cells with colspan, rowspan, align and valign, and tr with align. KOReader’s crengine style sheet (fb2.css, lines 77 to 82) draws a table at 80% size and full width with a 1px black border, th bold, centred on a #DDD background, and td with 3px padding. Calibre, crengine and Foliate keep a td a data cell, so the explorer does too: a table whose first row is all th gets a header row, any other table is shown as HTML with no header row. The explorer shows spans, align and valign; its table look is the site’s own, not crengine’s. |
| Notes bodies | The description says notes live in a body named notes, and a note link has type="note"; it adds that a book may hold several bodies, the first shown by default and the others reached by links. | crengine’s fb2.css styles body[name="notes"] and body[name="comments"] alike (lines 104 to 114), sets a note link as small raised text (line 10) and marks every body after the first non-linear (lines 119 to 121), quoting the same sentence of the description. calibre’s fb2_input.py (lines 114 to 129) pairs a note link with the target by its #id. The explorer shows every body one after another, each headed by its name, and a link to #id goes to that element. |
| Binary content types | The schema takes any string; the author’s 2.0 comments page says the programs of the time showed only PNG and JPG; the description says the library rejects other attachments and that GIF is not supported. | Foliate’s fb2.js (line 89) builds a data: URL from the stated type whatever it is. The explorer decides from the bytes (the sniffed type), not from the stated type, and draws a picture only when the page can draw it; otherwise the reading view says so. |
| Schema edition | The author publishes 2.0, 2.1 and 2.2 (the versions page). | The schema bundled with FictionBook Editor is the published 2.2 with one change: a poem may hold a subtitle beside its stanzas. The repository schema has that change and in addition requires the notes body to be named notes. So a book that FictionBook Editor writes may use subtitle in a poem, which the 2.2 schema alone rejects; the explorer follows the repository schema and so accepts it. |
| Table cell attributes | The schema names align and valign on td/th; no published schema has halign. | Okular’s converter.cpp reads halign (line 1109) and valign (line 1118) and not align, merges colspan (line 1102) and leaves rowspan as a TODO (line 1094); it draws every table without a border (line 1038) and th in bold (line 1079). The explorer reads align as the schema says and shows rowspan. |
| Text whitespace and unknown inline elements | The description treats a paragraph as text with inline markup. | Okular collapses the whitespace of every text node (simplified(), line 620) and, in a paragraph, handles only emphasis, strong, style (its text only, line 680), a, image, strikethrough, code, sup and sub (lines 581 to 617); any other element is dropped with its text. MuPDF keeps a list of 31 FB2 tag names (html-parse.c, lines 188 to 193; the description elements in it are only description, title-info and coverpage), shows the coverpage of the title-info and hides the rest of description (lines 114 to 117), and takes title, authors and the annotation text as metadata (lines 2228 to 2263). The explorer shows every part of the description in its own tab. |
| Stylesheet and binary objects in MuPDF | A stylesheet element holds a CSS text and each binary a base64 body with an id and a type. | MuPDF parses the first stylesheet as CSS after its own defaults (fb2_load_css, lines 1724 to 1746), hides stylesheet and binary (line 113), decodes every binary that has an id as base64 and lets its image loader decide the format, ignoring the stated type (load_fb2_images, lines 1749 to 1786), and resolves an image through l:href or xlink:href only for a value that starts with # (gen2_image_fb2, lines 1352 to 1362). Okular (line 694) decodes the first text node of a binary and lets Qt’s image loader decide. The explorer also decides from the bytes. |
| Recognising a file | The root element is FictionBook in the namespace of the schema. | MuPDF accepts a file whose first 4096 bytes contain the text <FictionBook, by extension fb2 or xml (html-doc.c, lines 610 to 661). Okular refuses a document whose root element is not FictionBook (line 99). The explorer reads the root element and its namespace. |
| Zipped books and encodings in FBReader for Android | The encoding is the one in the XML declaration; the format has no zip rule. | FB2NativePlugin.java accepts a .fb2.zip archive only if it holds exactly one child with the extension fb2; with none or with two it throws “incorrectFb2ZipFile” (lines 77 to 94, 68 to 75). It sets the encoding to auto (lines 100 to 108). A link target that is not found is retried with the identifier URL-decoded as UTF-8 and as windows-1251 (lines 44 to 65). Its annotation reader (FB2AnnotationReader.java) stops at the first body, takes the text of annotation, one line per p (lines 57 to 84). The parsing itself is native code (NativeFormatPlugin, line 36), which is the C++ already read above. |
empty-line | The description says it “has no content”; the schema gives it no type, so the schema accepts content. | calibre writes a br and ignores any content. The explorer reports content in an empty-line as a problem, naming this difference. |
| Genre codes | The list differs in each published schema (genres page). | calibre’s metadata reader reads the genre text and does not check it against any list. The explorer accepts a code that any published list has and says which lists have it. |
Not described
Every element, attribute and genre code of the published schema is on these pages; the gaps are around the schema.
Known, not yet covered
- Reference: FictionBookLang.xsd and FictionBookLinks.xsd hold no
lists: the first declares
xml:langas an XML Schemaxs:language, the secondxlink:type(fixed tosimple) andxlink:href. The elementlangis a plain string in the schema, so the viewer only checks that it looks like a language code. - Viewer: the schema is checked in two ways that agree: the explorer’s hand-written
rules for each element, and a small XML Schema validator that runs FictionBook.xsd itself. The validator
covers exactly the constructs the file uses:
xs:element(named, with a type or an inline type,minOccursandmaxOccurs),xs:complexType(also mixed),xs:sequenceandxs:choicenested and repeated,xs:complexContentandxs:simpleContentwithxs:extension,xs:attribute(name or ref, type,use,fixed, an inline type),xs:simpleTypewithxs:restrictionand the facetsxs:enumerationandxs:pattern(the only ones the schema has), and the types string, token, ID, float, integer, date, gYear, language and base64Binary. It does not doxs:all,xs:any,xs:union,xs:list, keys, other facets or other schemas, because FictionBook.xsd has none of them. Three things are approximations: an element with no type (empty-line) is the XSD “any type”, which accepts content, so the explorer’s own rule is what says it must be empty; the number range ofxs:floatis checked by shape; and the imported schemas for genres,xml:langandxlinkare built in (the genre list from FictionBookGenres.xsd, the others from FictionBookLang.xsd and FictionBookLinks.xsd). The reading view shows emphasis, strong, strikethrough, sub and sup, code, links (a note link goes to the note), poems with their stanzas, epigraphs, citations, tables (withcolspan,rowspan,alignandvalign) and pictures inline. A FictionBook 3 (.fb3, a ZIP of XML) file is a different format and is not read. - Viewer: the
text/cssstylesheets are shown in the Description tab, rule by rule. The reading view applies the class rules that name a style (.name,p.nameor*.name, matching astyleelement’s or astyleattribute’s name) for these properties only:font-weight,font-style,text-decoration,vertical-align(sub, super),font-size(smaller, larger),colorand the firstfont-family. Every other declaration, and every other kind of selector, is listed as not applied; a stylesheet of another type is listed, not applied. A whole CSS engine (layout, margins, other properties and selectors) is not built, so a book that depends on it looks different from its reading in a program that has one. - Viewer: the explorer holds the whole document for the book view and the schema check, up to 128 MiB (a 50 MB book takes about 4 seconds). A larger file is still recognised as a FictionBook, and opens on the XML tabs, which read it in windows, with a problem saying that the description, reading view and schema problems were not made. Nothing is hidden, but those parts are not offered for such a file.
- Viewer: the schema is the only measure: it reports nothing the schema accepts (an empty
first-name, padded token values, any integer formatch,colspanorrowspan, a binary of any content type), checked againstxmllint --schema FictionBook.xsdon real books. Where a hand-written rule and the schema find the same fault, it is reported once. What the schema does not say, such as a declaration of a single-byte encoding over UTF-8 bytes, is reported with the reason. The FictionNotes markup format (reader notes and bookmarks, described on the Description page) opens as plain XML, not as notes.
Unknown
- Reference: the 2.1 and 2.2 descriptions were found in the Internet Archive’s copy of the fictionbook.org wiki and are summarised under
the versions: the 2.1 changes page, the 2.1 genre page and the 2.2 schema page. The wiki holds no prose
description of 2.2 beyond its schema, and its per-element pages are mostly schema fragments (the one for
outputis unfinished), so what the authors meant byoutputbeyond the schema’s own documentation is not written anywhere found. - Reference: the origin of one rule in the schema of the
gribuser/fb2repository: the notes body must be namednotes. The version itself is settled by the versions: Kondratovich’s book (section “Версии 2.2 и 2.21”) says 2.21 (January 2008) changed the genre list (sci_businessout, twelve business genres in) and allowed subtitles in poems, which the repository’s file has. The book does not mention the notes-body rule, and no source read dates it. (The Softpedia changelog that might say more refused every fetch, and the Internet Archive’s copy of it could not be fetched here.) - Reference: the content of a book in the namespace
…/fictionbook/2.1that calibre reads: no schema for that namespace could be found (all published schemas use the 2.0 namespace), so the explorer applies the 2.0-namespace schemas to it. - Reference: what SumatraPDF does: its repository (
sumatrapdfreader/sumatrapdf) has no FB2 source file by name insrc/and carries MuPDF inext/mupdf, but no Sumatra source that routes FB2 to MuPDF was read, so Sumatra’s behaviour is taken to be unread; MuPDF’s own handler is described above. The sources of legacy FBReader (C++), FBReader for Android, calibre, KOReader’s crengine, Foliate, Okular, MuPDF and FictionBook Editor’s schema are covered above; the Java file of FBReader for Android only wraps the native parser, which is the C++ read earlier. - Reference:
foreign_descis listed by Flibusta as “foreign reference literature” (flibusta.info/g), and no schema or program documentation read defines it; genre codes that libraries use but the schema does not list are on the genres page. FB3 is a different format.
Links
Software
- FBReader – ebook reader named after the format (Windows, macOS, Linux, Android, iOS)
- calibre – free ebook library manager, reader and converter (Windows, macOS, Linux)
- KOReader – free reader for e-ink devices (e-readers, Android, Linux)
- SumatraPDF – small, fast free viewer that reads FB2 (Windows)
Reference
- gribuser/fb2 – the FictionBook XML schemas, including the genre list (XSD)
- FB2 – the MobileRead Wiki’s page on FictionBook