How7oHow7o
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Set A4 Paper Size in CSS for Print
Share
Notification Show More
Font ResizerAa
How7oHow7o
Font ResizerAa
  • Tools
  • Prank Screens
  • Learn
  • Blog
Search
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Set A4 Paper Size in CSS for Print
Web Development

How to Set A4 Paper Size in CSS for Print

how7o
By how7o
Last updated: May 23, 2026
5 Min Read
Set A4 paper size in CSS for printing
SHARE

To set A4 paper size in CSS for printing, declare @page { size: A4; } at the top of your stylesheet. Pair it with a @media print block that sets the body’s width and height to A4 dimensions (210mm × 297mm) so the layout matches the paper. Browsers honor this when printing or exporting to PDF.

Contents
  • The CSS
  • Other common paper sizes
  • Sensible print margins
  • Page breaks
  • Test it
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 in Chrome 124, Firefox 125, Safari 17. Originally published 2022-10-20, rewritten and updated 2026-05-17.

The CSS

@page {
    size:   A4;
    margin: 0;
}

@media print {
    html, body {
        width:   210mm;
        height:  297mm;
        margin:  0;
        padding: 0;
    }
}
  • @page defines the printed page’s box — paper size and margins. size: A4 is the keyword the browser maps to 210 × 297 mm.
  • margin: 0 removes the browser’s default printable-area margin so content fills the sheet edge-to-edge (most printers still keep a small unprintable border).
  • @media print sets explicit dimensions on the layout root, so your content’s measurements match the page. Useful when the on-screen design uses different sizes.
CSS @page A4 — size keyword, margin reset, landscape orientation, common paper sizes

Other common paper sizes

@page { size: A4; }          /* 210 × 297 mm   — international standard */
@page { size: Letter; }      /* 8.5 × 11 in    — US/Canada */
@page { size: Legal; }       /* 8.5 × 14 in    — US legal */
@page { size: A3; }          /* 297 × 420 mm */
@page { size: A5; }          /* 148 × 210 mm */
@page { size: A4 landscape; }/* A4 sideways */

/* Custom — explicit dimensions */
@page { size: 100mm 150mm; }

Sensible print margins

@page {
    size:   A4;
    margin: 20mm 15mm;       /* top/bottom 20mm, left/right 15mm */
}

For documents (not edge-to-edge invoices), keep a reasonable margin. Browsers and printers tend to give better results when the margin is set explicitly rather than left to the default.

Page breaks

/* Force a break before this element */
.new-page {
    break-before: page;
}

/* Avoid breaking inside */
.invoice-row {
    break-inside: avoid;
}

/* Avoid breaking right after a heading */
h2 {
    break-after: avoid;
}

Use break-* properties (modern names for the legacy page-break-*) to control where the printer breaks pages. Especially important for tables and multi-section documents.

Test it

  • Open the page in Chrome/Firefox/Safari.
  • Press Ctrl+P (Cmd+P on macOS) to open the print preview.
  • Confirm “Paper size” shows A4 and the layout matches the design.
  • Choose “Save as PDF” to generate a deterministic preview file you can share.

Frequently asked questions

Does @page work in every browser?

Yes — @page with size and margin is supported in every modern browser when printing or generating a PDF via the browser’s print dialog. The keywords (A4, Letter, Legal, A3, etc.) are part of the CSS spec. The user can still override the paper size from the print dialog — your @page sets the default.

What’s the difference between A4 as a keyword and explicit 210mm 297mm?

The keyword tells the print engine “this is A4 paper” — it picks the right physical paper from the printer when a real printer is involved. The explicit dimensions only define the page layout box. For browser PDF export they’re equivalent; for physical printing the keyword is more reliable.

Why margin: 0 — won’t content go to the edge?

Yes, intentionally — for an invoice or label that needs to fill the sheet, margin: 0 on @page removes the browser’s default print margins (usually 0.5in). Most home printers can’t actually print to the physical edge (there’s a hardware unprintable border), so you’ll still see a small white gutter. Test on the target printer.

How do I do landscape orientation?

Add it to @page: @page { size: A4 landscape; margin: 0; }. Common combos: size: A4 portrait (default), size: A4 landscape, size: Letter, size: Letter landscape. For mixed orientations within one document, use named pages with @page name { size: A4 landscape; } and apply page: name on specific elements.

Related guides

  • How to Change the Background Color of a Checkbox with CSS
  • Page Breaks Not Working with Tables in HTML / CSS

References

MDN @page: developer.mozilla.org/en-US/docs/Web/CSS/@page. MDN size: developer.mozilla.org/en-US/docs/Web/CSS/@page/size. MDN break-before/after/inside: developer.mozilla.org/en-US/docs/Web/CSS/break-before.

TAGGED:CSSlayoutprint

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Enforce a minimum phone-number length in WooCommerce checkout How to Set a Minimum Length for Phone Numbers in WooCommerce
Next Article Set and get cookies with JavaScript How to Set and Get Cookies with JavaScript
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

You Might Also Like

Check Bootstrap modal open or closed with jQuery
Web Development

How to Check if a Bootstrap Modal Is Open or Closed with jQuery

4 Min Read
Get the index in a jQuery each loop
Web Development

How to Get the Index in a jQuery .each() Loop

4 Min Read
Find prime numbers in JavaScript thumbnail
Web Development

How to Find Prime Numbers in JavaScript (1 to 100) — Fast & Simple Methods

5 Min Read
MySQL 8 create user and grant privileges on Ubuntu
Web Development

How to Create Users and Grant Privileges in MySQL 8 on Ubuntu

8 Min Read
How7oHow7o

Free browser-based tools, prank screens, and step-by-step tech tutorials. No signup, nothing uploaded.

  • Private by design — your files never leave your device
  • Instant — no signup, no install, no waiting
  • Always free — no trials, no watermarks, no paywalls

Tools

  • PDF Editor
  • Image Upscaler
  • JPEG Compressor
  • Password Generator
  • QR Code Generator
  • Video Trimmer
  • See all tools →

Pranks

  • Cracked Screen Prank
  • Fake Blue Screen (BSOD)
  • Fake Disk Format
  • Fake Low Battery
  • Fake Nintendo Switch Update Screen
  • Fake PlayStation Update Screen
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?