Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 6
    Add display: block; and it does the job.
    – superlukas
    Commented Aug 20, 2014 at 12:40
  • 21
    I tried this and found that in Chrome and Firefox, the canvas simply shows the image stretched to the full viewport. Even newly drawn elements are stretched, as well. Commented Aug 21, 2014 at 3:03
  • 9
    @Daniel is right - this answer is wrong. It won't set the internal dimension of the canvas context, but rather the dimensions of the DOM element. For the difference, see my answer to a related question. Commented Jul 3, 2015 at 2:32
  • 32
    This method does not work, it stretches the text. You unfortunately have to use JS.
    – i336_
    Commented May 10, 2016 at 1:56
  • There are cases where you want to stretch (i.e. progress bar). Thanks, great for my case! Commented Oct 14, 2020 at 6:59