How to print page in HTML
All you need to do is use click event and fire a javascript function
If you need to hide a section on the page while printing or need to do any specific CSS change while printing (like hiding print button) use this media tag in CSS:
window.print();
on it. Here is an example:<button class="hide-to-print" onclick="window.print();" type="button">Print</button>
If you need to hide a section on the page while printing or need to do any specific CSS change while printing (like hiding print button) use this media tag in CSS:
@media print
Source Code:
<!DOCTYPE html>
<html>
<head>
<title>How to print page in HTML | MG Technologies</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
@media print {
.hide-to-print {
display: none;
}
}
</style>
</head>
<body>
<h2>Click on the button to print this page</h2>
<button class="hide-to-print" onclick="window.print();" type="button">Print</button>
<h3>What is Lorem Ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<h3 class="hide-to-print">I'm not printable</h3>
</body>
</html>
Free - Download it right now!
Tested
Include all files
Demo DownloadUnlock Your Free Download for Just $2