In this article I will explain how to print DIV contents with CSS styles using JavaScript and jQuery without using any jQuery Print plugin.
When one tries to print a DIV with CSS styles applied from an external CSS file, the contents are printed without the CSS styles. Thus using the following trick one can print the DIV contents with the CSS styles.
HTML Markup
The HTML Markup consists of an HTML DIV which is styled using an external CSS file and a Button for printing the HTML DIV contents.
<link href="style.css" rel="stylesheet" type="text/css" />
<div id="dvContents">
   <div class="left">
        <img alt="" src="images/ASPSnippets.png" />
    <div class="right">
        <span class="label"> Sample page</span>
    <div class="clear">
    <hr />
    <div class="contents">
        <span class="label">Hello,
            <br />
            This is <span class="name">Mudassar Khan</span>.<br />
            Hoping that you are enjoying my articles!</span>
<br />
<input type="button" id="btnPrint" value="Print" />
External CSS file
The following external CSS file contains the styling for the HTML DIV.
    font-size: 10pt;
    font-weight: bold;
    font-family: Arial;
    border: 1px dotted black;
    padding: 5px;
    width: 300px;
    color: #18B5F0;
    float: left;
    width: 50px;
    height: 50px;
    margin-left: 60px;
    clear: both;
Printing DIV contents with CSS using JavaScript and jQuery
When the Print button is clicked, first the contents of the HTML DIV to be printed are extracted.
Then a dynamic IFRAME is created and the extracted contents of the HTML DIV are written to the IFRAME along with the link to the external CSS file and finally the IFRAME document is printed using the JavaScript Window Print command and the IFRAME is removed from the page.
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(function () {
    $("#btnPrint").click(function () {
        var contents = $("#dvContents").html();
        var frame1 = $('<iframe />');
        frame1[0].name = "frame1";
        frame1.css({ "position": "absolute", "top": "-1000000px" });
        var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;;
        //Create a new HTML document.
        frameDoc.document.write('<html><head><title>DIV Contents</title>');
        //Append the external CSS file.
        frameDoc.document.write('<link href="style.css" rel="stylesheet" type="text/css" />');
        //Append the DIV contents.
        setTimeout(function () {
        }, 500);
HTML DIV Contents
Print DIV contents with CSS using JavaScript and jQuery
Printed HTML DIV with CSS
Print DIV contents with CSS using JavaScript and jQuery
Browser Compatibility

The above code has been tested in the following browsers.

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.