Skip to content
Related Articles

Related Articles

How to resize an image in an HTML 5 canvas ?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 27 Aug, 2019

The canvas element is part of HTML 5 and it allows the rendering of 2D shapes and bitmap(also called “raster”) images.
A canvas actually has two sizes:

  • the size of the element.
  • the size of the element’s drawing surface.

The element’s width and height attributes set both the size of the element and the size of the element’s drawing surface. CSS attributes affect only the element’s size and not the drawing surface.


<!DOCTYPE html>
    <img id="forest" width="220" height="277" src=
    <canvas id="Canvas" width="300" height="200"
                style="border:15px solid #000066;">
        Your browser not support the HTML5 canvas .
        window.onload = function() {
            var canvas = document.getElementById("Canvas");
            var context = canvas.getContext("2d");
            var img = document.getElementById("forest");
            context.drawImage(img, 12, 8);


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!