Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control page margin when printing HTML document?

Tags:

css

padding

I'm printing a long HTML document and i want to set the margin between the pages in the CSS file. Unfortunately, the padding/margin only take effect in the first page (padding-top) and the last page (padding-bottom).

Any way to set the margin between pages?

like image 547
amit Avatar asked Oct 18 '25 14:10

amit


1 Answers

It's not margin between pages but page margin. It's controlled by a specific CSS media @page:

@page {
    margin: 1cm;
}

Please refer to linked specs for all the details (especially about how @page combines with, for example, <body> margins).

Note that with pseudo-selectors you can control the aspect of :left, :right and :first pages (just to mention few common use cases).

like image 152
Adriano Repetti Avatar answered Oct 21 '25 06:10

Adriano Repetti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!