Home > Article > Web Front-end > Can I Set Print Margins for HTML Pages Using CSS?
Setting Margins When Printing HTML Pages
When printing HTML pages, you may need to adjust the left and right margins to ensure the printout conforms to the margins defined by your printer.
Is it possible to set print margins in a CSS style sheet?
Yes, you can set page margins using cm or mm units in your CSS style sheet. For example:
<code class="css">body { margin: 25mm 25mm 25mm 25mm; }</code>
Using cm or mm ensures consistent margin sizes on paper, regardless of screen resolution.
Additional Considerations:
Example Using body and @page Directives:
<code class="css">body { margin: 0px; /* Margin for content within the HTML body */ } @page { size: auto; margin: 25mm 25mm 25mm 25mm; /* Margin for paper outside the body */ }</code>
The above is the detailed content of Can I Set Print Margins for HTML Pages Using CSS?. For more information, please follow other related articles on the PHP Chinese website!