Is it possible to print HTML pages with custom headers and footers on each printed page?
I'd like to add the word "UNCLASSIFIED" in Red, Arial, size 16pt to the top and bottom of every printed page, regardless of the content.
To clarify, if the document was printed onto 5 pages, each page should have the custom header and footer.
Does anybody know if this is possible using HTML/CSS?
I found one solution. The basic idea is to make a table and in thead section place the data of header in tr and by css force to show that tr only in print not in screen then your normal header should be force to show only in screen not in print. 100% working on many pages print. sample code is here
I just spent the better half of my day coming up with a solution that actually worked for me and thought I would share what I did. The problem with the solutions above that I was having was that all of my paragraph elements would overlap with the footer I wanted at the bottom of the page. In order to get around this, I used the following CSS:
The
page-break-inside
forp
andcontent-block
was crucial for me. Any time I have ap
following anh*
, I wrap them both in adiv class = "content-block">
to ensure they stay together and don't break.I'm hoping that someone finds this useful because it took me about 3 hours to figure out (I'm also new to CSS/HTML, so there's that...)
EDIT
Per a request in the comments, I am adding an example HTML document. You'll want to copy this into an HTML file, open it, and then choose to print the page. The print preview should show this working. It worked in Firefox and IE on my end, but Chrome made the font small enough to fit on one page, so it didn't work there.
If you take the element that you want to be the footer and set it to be position:fixed and bottom:0, when the page prints it will repeat that element at the bottom of each printed page. The same would work for a header element, just set top:0 instead.
For example:
CSS:
I have been searching for years for a solution and found this post on how to print a footer that works on multiple pages without overlapping page content.
My requirement was IE8, so far I have found that this does not work in Chrome. [update]As of 1 March 2018, it works in Chrome as well
This example uses tables and the tfoot element by setting the css style:
Based on some post, i think
position: fixed
works for me.Press Ctrl+P in chrome see the header & footer text on each page. Hope it helps
i believe the correct answer is that HTML 5 and CSS3 have no support for printing page header and footers in
print
media.And while you might be able to simulate it with:
they each have bugs that prevent them from being the ideal general solution.