@page { /* width and height. In this case for an A5 */ size: 148.5mm 210mm; /* OR */ /* size: A5 portrait; */ padding: 0; marks: crop; bleed: 5mm; margin: 25mm; /* Bigger bleed as weasyprint draws the cropmarks within the bleed*/ } @page { @bottom-center { /** On every page display the value of the page counter at the bottom center. The page counter is a special counter created by weasyprint. */ content: counter(page); } } @page:right { /** Use a pseudo-selector on the page to display page numbers on right pages on the right. */ @bottom-right { content: counter(page); } } @page:left { /** Use a pseudo-selector on the page to display page numbers on left pages on the left. */ @bottom-left { content: counter(page); } } @page:first { /** Selects the first page of the documents. Allows for example for hiding the page numbers on the cover and / or different page margins there. */ } @page:empty { /** According to the standards this selector should select empty pages. In my experience it doesn't always work. */ } /** Running headers */ h1 { /** When a header 1 is encoutered set the value of the string running-header to the value of the header */ string-set: running-header content(text); } @page { @bottom-center { /** On every page display the value of running-header at that moment */ content: string(running-header); } } #toc li a::after { float: right; content: target-counter(attr(href), page); }