Can you take a screenshot of the page using HTML5 Canvas?

Html2Canvas is a JavaScript library that can take screenshot of the whole web page or specific part. It doesn’t take the screenshot but creates the view based on the page information.


Below given is an example code. Here, html2canvas.js script is included at the <head>. The html2canvas() method is called. Returns the base64 value, which eventually creates image source or an image file.

<!DOCTYPE html>
      <script src="html2canvas-master/dist/html2canvas.js"></script>
      <h1>Take screenshot</h1>
      <div class="container" id='container' >
         <imgsrc='images/one.jpg' width='50' height='50'>
         <imgsrc='images/two.jpg' width='50' height='50'>
      <input type='button' id='but_screenshot' value='Take screenshot' onclick='screenshot();'><br/>
         function screenshot(){
            html2canvas(document.body).then(function(canvas) {

Updated on: 24-Jan-2020


Kickstart Your Career

Get certified by completing the course

Get Started