devxlogo

Create Page Breaks in an HTML Document

Create Page Breaks in an HTML Document

Question:
Is there any way (using an HTML tag or a script) to force a page break at a certain point in an HTML document when it is being printed? For example, my Web page is about five printed pages long. When it is being printed, I would like to control where the page breaks occur.

Answer:
In Internet Explorer 4, you can make use of two Cascading Style Sheets (CSS) style attributes: page-break-before and page-break-after. They can be applied as individual attributes within a style tag, or you can create a generalized DIV with a specific class that incorporates the command. These attributes will give no visual indication of the page-break in the on-screen representation of the page, but will cause a break when the document is printed.

For example, if I wanted to break the page after a table, I’d use the option:

...

Both page-break-before and page-break-after can take one of four values:

auto: (default) the page will break at the end of the element if it’s at the logical end of the page (in other words, the regular printing occurs)

always: the page will always break at the indicated location.

left: insert one or two page breaks after the object until a blank left page has been reached.

right: insert one or two page breaks after the object until a blank right page has been reached.

See also  How College Students Can Shape the Future of Tech Responsibility
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist