Web Design / HTML

  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 Jennifer Kyrnin, About.com

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.

More Web Design / HTML Q&A

Explore Web Design / HTML

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Web Design / HTML

  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.