# HTML #
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="print.js"></script>
<link rel="stylesheet" href="print.css">
</head>
<body>
<button type="button" onclick="printDoc()">Print</button>
<p id="myId">Hello, I am Thet Naing Win. Welcome to zilastar.com.</p>
</body>
</html>
# CSS #
body{
color: red;
}
# JavaScript #function printDoc(){
var printDoc = document.getElementById("myId").innerHTML;
var a = window.open('', '', 'width=auto; height=auto');
a.document.write("<html><head><title>ZilaStar</title>");
a.document.write("<link rel='stylesheet' href='print.css'>");
a.document.write("</head>");
a.document.write("<body>");
a.document.write(printDoc);
a.document.write("</body>");
a.document.write("</html>");
a.focus();
setTimeout(function(){
a.print();
setTimeout(function(){
a.close();
}, 500)
}, 500);
}