Page Margins
Running heads, page numbers, thumb tabs: everything printed in a page's margins is the style's design, written in its CSS. What those margins say comes from the book: its title from typoteka.json, its chapter and section names from the Markdown. A style should not write a particular book's words into its stylesheet, so that any book can use it.
This page is for whoever writes a style of their own. Everything here works from the style's CSS alone.
Margin boxes
A page has sixteen boxes around its text area, named by the CSS paged-media standard. You fill one by giving it content inside an @page rule:
text
┌──────────────┬──────────┬────────────┬───────────┬───────────────┐
│ top-left- │ top-left │ top-center │ top-right │ top-right- │
│ corner │ │ │ │ corner │
├──────────────┼──────────┴────────────┴───────────┼───────────────┤
│ left-top │ │ right-top │
│ left-middle │ the text │ right-middle │
│ left-bottom │ │ right-bottom │
├──────────────┼──────────┬────────────┬───────────┼───────────────┤
│ bottom-left- │ bottom- │ bottom- │ bottom- │ bottom-right- │
│ corner │ left │ center │ right │ corner │
└──────────────┴──────────┴────────────┴───────────┴───────────────┘css
@page {
@bottom-center {
content: counter(page);
font-size: 9pt;
}
}A box takes any text styling: font-family, font-size, color, text-align, vertical-align, background, padding, writing-mode, transform.
Left and right pages
:left (verso) and :right (recto) style the two sides of a spread separately. This is how a design mirrors its running heads and page numbers toward the outer edge:
css
@page :left {
@top-left { content: string(book-title); }
@bottom-left { content: counter(page); }
}
@page :right {
@top-right { content: string(chapter-title); }
@bottom-right { content: counter(page); }
}What the book provides
The shared layer every style builds on keeps these up to date as the pages are laid out. Print them with string():
| Name | Holds |
|---|---|
book-title | The book's title in typoteka.json. |
chapter-title | The current chapter: the # heading that opened it. |
section-title | The current section: the ## heading that opened it. |
Chapter and section names come in their short form when the author gave one (see short titles), and in full otherwise. Section numbers and footnote marks are left out.
Texts and literals mix freely in one box:
css
@top-center { content: string(book-title) " · " string(chapter-title); }Strings of your own
Every heading carries two attributes a style can read:
data-title: its full text, clean.data-short: its short form if the author gave one, else the same full text.
Feed a string of your own from them with string-set and attr():
css
h3[data-short] {
string-set: topic attr(data-short);
}
@page :right {
@top-center { content: string(topic); }
}Read headings through these attributes, not with content(text). content(text) takes everything inside the heading, including the section number (hidden on the page, but there all the same) and footnote marks: a head would read "2.1 The Rules" or "The Rules1".
Which one on the page
A page can hold several headings. The second argument of string() says which one to print:
| Form | Prints |
|---|---|
string(x) or string(x, first) | The first one set on this page, else the one carried over from earlier pages. |
string(x, start) | The one in force when the page begins. |
string(x, last) | The last one set on this page. |
string(x, first-except) | Nothing on the page where it is set; elsewhere, like first. |
A dictionary or a glossary puts the first and the last entry of each page at its top:
css
h2[data-short] { string-set: entry attr(data-short); }
@page :right {
@top-left { content: string(entry, first); }
@top-right { content: string(entry, last); }
}first-except keeps a chapter's name out of the head of the very page where its title is printed in large type.
Page numbers
counter(page) is the page number and counter(pages) the number of pages in the book, front matter included. Any list style applies:
css
@bottom-right { content: counter(page) " of " counter(pages); }Front matter numbered in roman, with the main text starting again at 1, uses a named page for the front matter and a reset where the main text begins. Numbering carries on from the reset to the end of the book. The classes are your style's vocabulary; document them on the style's page so authors know to write # Preface {.front} and # Chapter One {.main}:
css
section.front { page: front; }
@page front {
@bottom-center { content: counter(page, lower-roman); }
}
section.main { counter-reset: page 1; }Pages that show less
First page:
@page :first.Blank pages (the ones inserted to start a chapter on a right page):
@page :blank. To leave them empty, clear every box your design fills:css@page :blank { @top-left { content: none; } @top-right { content: none; } @bottom-center { content: none; } }Covers: a
::: coverblock is on the named pagecover, which has no margins and nothing in them (see Covers).Other special pages: give the element a named page (
.map { page: map; }) and style@page map.The page where a chapter opens: put every chapter on a named page and style its first page:
csssection.level1 { page: chapter; } @page chapter:first { @top-left { content: none; } @top-right { content: none; } @bottom-center { content: counter(page); } }
An element has one page name. A chapter your style already sends to another named page (a one-column layout, say) does not get the chapter:first rules. A named page also always starts a new page.
Thumb tabs
A tab on the outer edge that steps down chapter by chapter, as some reference books have, needs the chapter's number. Every page carries it as two custom properties (a chapter is a ::: chapter block, or a # heading when the book's chapter headings setting is on):
--chapter-index: the current chapter's number, from 1 (0 before the first).--chapter-count: how many chapters the book has.
A chapter is a # heading's section.
css
@page :right {
@right-top {
content: string(chapter-title);
writing-mode: vertical-rl;
height: 18mm;
background: #333;
color: #eee;
transform: translateY(calc((var(--chapter-index) - 1) * 20mm));
}
}They are numbers, for calc(): content cannot print them.
Images and ornaments
A box's background takes an image, relative to the style's directory like any other url():
css
@page {
@bottom-center {
content: counter(page);
background: url(ornaments/footer.svg) no-repeat center bottom / contain;
}
}An element of the book can also be moved into a box, formatting and all: give it position: running(name) and print it with content: element(name). Only its first appearance is used, and the element has to come from the Markdown, so this suits something an author places once, such as a series logo.
Text that depends on the book's language
A box that prints a word of its own ("Chapter", "Page") can follow the book's language, which the book sets in typoteka.json. Pages are laid out in that language, so :lang() picks the word; define it as a custom property and print it with var():
css
:root { --label-chapter: "Chapter"; }
:lang(es) { --label-chapter: "Capítulo"; }
:lang(fr) { --label-chapter: "Chapitre"; }
@page :right {
@top-right { content: var(--label-chapter) ": " string(chapter-title); }
}Limits
One rule per string. Each named string is fed by a single selector: a second
string-setfor the same name replaces the first rather than adding a fallback. Redefiningchapter-titleorsection-titlein your style replaces the shared layer's.Page size and margins go in
style.json(margins) and the style's@page, never in custom properties:@pagedoes not resolvevar(). Inside margin boxes,var()works.!importanthas no effect inside@page.Base underneath. A style without
extendsin itsstyle.json(or without astyle.json) builds on Base, which prints the page number at the bottom centre. Clear it if your design puts it elsewhere:css@page { @bottom-center { content: none; } }