1. Home
  2. Computing & Technology
  3. Web Design / HTML

How do I print with CSS and have the page breaks in the right places?

By , About.com Guide

Question Mark Key

Question Mark Key

Image courtesy hdoddema from StockXchng #619007.
Question: How do I print with CSS and have the page breaks in the right places?

I got the following question from Nancy:

Often times, we have a picture and caption interspaced with the text. We would like the picture to print with the text and print the whole picture on the page with the text instead of the 1) picture printing on the next page 2) picture printing part on one page and part on another page.
Answer:

What you need to do is put a container element (like a div) around both the image and the text, then in your print style sheet, use the page-break-inside property set to "avoid":

page-break-inside: avoid;

Other style properties that might work for what you're looking for are page-break-before and page-break-after.

You should probably learn how to set up a print style sheet if you don't already know how.

Explore Web Design / HTML
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. Web Server Management
  5. Web Administration
  6. Printer Friendly
  7. How do I set up CSS to print and have the document put page breaks in the right place?>

©2009 About.com, a part of The New York Times Company.

All rights reserved.