HTMLCanvasElement.height

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

La propriété HTMLCanvasElement.height est un entier positif reflétant l'attribut HTML height de l'élément <canvas> mesuré en pixels CSS. Quand cet attribut n'est pas spécifié, ou si on lui affecte une valeur invalide, telle que négative, la valeur par défaut de 150 is utilisée.

C'est l'une des deux propriétés, l'autre étant HTMLCanvasElement.width, qui contrôlent la taille du canevas.

Syntaxe

js
var pxl = canvas.height;
canvas.height = pxl;

Exemples

Étant donné cet élément <canvas> :

html
<canvas id="canvas" width="300" height="300"></canvas>

vous pouvez obtenir la hauteur du canevas avec le code suivant :

js
var canvas = document.getElementById("canvas");
console.log(canvas.height); // 300

Spécifications

Specification
HTML
# dom-canvas-height

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
height

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi