Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <canvas> height Attribute

The height attribute on a <canvas> tag sets the height of the canvas.

The height is specified in pixels - without the ‘px‘ unit.

Example

#

A <canvas> element with a height attribute.

<canvas id="mycanvas" height="110" width="110"></canvas>

<script>

  ( () => {
    let canvas = document.getElementById("mycanvas");
    let context = canvas.getContext("2d");

    context.fillStyle = "lightblue";
    context.fillRect(5, 5, 100, 100);
  } )();

</script>

Using height

The height attribute specifies the height of the canvas.

The height is specified in pixels -- without the 'px' unit.

Percentages (%) are not allowed, but most browsers do support it.

The default height of a canvas is 150px.


Syntax

<canvas height="pixels" >

Values

#

Value Description
pixels Height of the canvas in pixels. The default is 150px.

Browser support

Here is when height support started for each browser:

Chrome
4.0 Jan 2010
Firefox
2.0 Oct 2006
IE/Edge
9.0 Mar 2011
Opera
9.0 Oct 2005
Safari
3.1 Mar 2008

You may also like

 Back to <canvas>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides