Can I display the number of the current page in the content?
Short answer: no.
The current page number can only be displayed inside the header and footer content.
Since header and footer are rendered on top of your Document's content, they have the knowledge of the "current" page. The content on the other hand is not aware of the page it's currently in.
That said, it can still be possible in some cases.
Exception: Powerpoint-like Documents
If you create a Powerpoint-like document where each page is fixed and content doesn't flow from one page to the next, you can use insert the page number using CSS counters.
Let's take the example of a portrait A4 page:
Here is what the result will look like.
Why use a CSS counter instead of adding the page number in the content?
You can add the page number in the content if you're sure that the content will never move and if all your pages are fixed.
The CSS counter technique is especially useful if
You want the page number to stay consistent even when the actual number of pages changes
Some pages are hidden/shown under certain conditions
Some pages are generated in a loop
It's just more robust overall and does not require that much more code.
Last updated