I am trying to print the page number on the HTML page, but nothing is working for me. I have already uses these codes
First code is here…
#content {
display: table;
}
#pageFooter {
display: table-footer-group;
}
#pageFooter:after {
counter-increment: page;
content: counter(page);
}
Second Code is here…
@page {
@bottom-left {
content: counter(page) ' of ' counter(pages);
}
}
I am waiting for your response. 🙂
2
Answers
No, you cannot directly print page numbers on an HTML page using CSS alone. CSS is primarily used for styling and layout purposes, and it doesn’t have built-in features for generating page numbers.
However, you can achieve this by using a combination of CSS and JavaScript or by utilizing CSS print media queries. Here are two approaches you can consider:
style the generated page numbers.
print rule. Inside the print media query, use the content property
with the counter() function to generate and display page numbers.
Define CSS styles to position and style the page numbers on the
printed pages.
For example:
In your HTML, add an element with the class "page-number" where you want the page number to appear. For example, refer to the last line in the above code.
When you print the page, the content property in the CSS will generate and display the page number on each printed page.
Remember that the second approach will only work when printing the page, not for displaying page numbers on the screen.
You should use CSS and JavaScript
this video can help try it.
https://www.youtube.com/watch?v=-fhJJYtguWI