Print contents of an HTML element with client-side JavaScript

Printing only a specific part of a web page will keep other page elements, that are not useful on paper (navigation, framing ect.), from taking up space on the printout.

Try it out: Print only the main content of this page without the menu and header/footer.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>JavaScript printing</title>
<script type="text/javascript">
  var win=null;
  function printIt(printThis)
    win =;
    win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
<a href="#" onclick="printIt(document.getElementById('printme').innerHTML); return false">
<br />
<div id="printme">Only this part of the page is printed</div>
Page last updated 2008-09-05 21:39. Some rights reserved (CC by 3.0)