Skip to content

Footnotes and paged-media features

Besides page setup (Pages), kolinsky reads the features of CSS Generated Content for Paged Media that books and reports use: footnotes, running elements, named strings, cross-references and leaders. This small book uses them together:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>A short book</title>
<style>
  @page {
    size: A5;
    margin: 20mm 15mm;
    @top-center { content: element(header) }
    @bottom-right { content: counter(page) }
    @footnote { border-top: 0.5pt solid #999; padding-top: 2mm }
  }
  body { font: 10pt/1.4 serif }
  /* a running element: taken out of the flow, shown in the top margin of every page */
  .running-title { position: running(header); font: italic 8pt sans-serif }
  h2 { break-before: page }
  /* footnotes */
  .note { float: footnote; font-size: 8pt }
  ::footnote-call { color: #c25129 }
  ::footnote-marker { font-weight: bold }
  /* table of contents: page numbers of the targets after a dotted leader */
  .toc a { color: inherit; text-decoration: none }
  .toc a::after { content: leader(dotted) target-counter(attr(href), page) }
  .ref::after { content: target-counter(attr(href), page) }
</style>
</head>
<body>
  <div class="running-title">A short book</div>
  <h1>Contents</h1>
  <ul class="toc">
    <li><a href="#one">The first chapter</a></li>
    <li><a href="#two">The second chapter</a></li>
  </ul>
  <h2 id="one">The first chapter</h2>
  <p>Paged media needs footnotes.<span class="note">This text goes to the bottom of the page.</span>
     The call stays in the text.</p>
  <h2 id="two">The second chapter</h2>
  <p>As shown in “<a href="#one">the first chapter</a>” on page
     <a href="#one" class="ref"></a>, footnotes are numbered through the document.<span class="note">This is the second footnote.</span></p>
</body>
</html>
kolinsky render gcpm_book.html -o gcpm_book.pdf

Footnotes

An element with float: footnote becomes a footnote. In its place the text gets a footnote call, and the element itself moves to the footnote area at the bottom of the page that holds the call:

.note { float: footnote; font-size: 8pt }
<p>Paged media needs footnotes.<span class="note">This text goes to the bottom of the page.</span></p>
  • Numbering. The footnote counter starts at 0 and each footnote adds 1, through the whole document; a page break does not reset it, and neither does counter-reset in an @page rule. A counter-reset on an element (for example body { counter-reset: footnote 10 }) does.
  • The call is the ::footnote-call pseudo-element of the footnote. By default it is content: counter(footnote) in a smaller font with vertical-align: super. It inherits from the footnote element, not from the text around it. The call is not a link.
  • The marker is the ::footnote-marker pseudo-element at the start of the footnote, by default content: counter(footnote) ". ". Both take any counter style: ::footnote-call { content: "[" counter(footnote, lower-alpha) "]" }.
  • The area is styled with an @footnote rule inside @page: margins, borders, padding, background and max-height. By default it has a top margin of 1em. It exists only on pages that hold footnotes, sits at the bottom of the page's content area and makes the room for the page's content shorter by its height.
@page {
  @footnote { border-top: 0.5pt solid #999; padding-top: 2mm; max-height: 60mm }
}

footnote-display sets how footnotes stand in the area: block (the default) puts each on its own lines, inline lets several short footnotes share a line (compact is treated as inline).

footnote-policy decides what happens when a footnote does not fit on the page of its call:

value effect
auto (default) the line with the call stays; the footnote, and every later one, moves to the next page
line the line with the call moves to the next page together with its footnote
block the whole paragraph with the call moves to the next page together with its footnote

A footnote is never split across pages and never placed before the page of its call.

Running headers and footers

Named strings copy text from the document into a margin box. string-set stores the text, string() shows it:

h1 { string-set: chapter content() }
@page { @top-left { content: string(chapter) } }

content() is the element's text; attr(), counter(), content(before), content(after) and literal strings can be combined. The second argument of string() picks the value when a page sets the string more than once: first (default), last, start (the value in effect at the top of the page) or first-except (nothing on the page where the string is set).

Running elements move a whole element, with its formatting, into a margin box. position: running(NAME) takes the element out of the flow, and element(NAME) in a margin box shows it on its page and the following ones:

.running-title { position: running(header) }
@page { @top-center { content: element(header) } }

element() takes the same first, last, start and first-except keywords, and all-once for every element of that name on the page.

Cross-references and tables of contents

target-counter() gives the value of a counter at the target of a link, target-text() its text. Used in ::after or ::before of links, they build tables of contents and "see page N" references:

.toc a::after { content: leader(dotted) target-counter(attr(href), page) }
a.ref::after { content: " (see “" target-text(attr(href)) "” on page " target-counter(attr(href), page) ")" }

The link is attr(href) or a string such as "#chapter-2". target-counter(attr(href), page, lower-roman) takes a counter style. target-text() accepts content (default), before, after and first-letter. Page numbers of targets later in the document are filled in by laying the document out again when needed. A target that does not exist ends the generated content at that point.

leader() fills the rest of the line with a pattern: leader(dotted), leader(solid), leader(space) or any string, leader(" . "). The text after the leader is aligned to the end of the line.

Bookmarks

bookmark-level, bookmark-label and bookmark-state build the PDF outline; h1 to h6 are bookmarks by default. See Links, bookmarks and the outline.