/

HTML / CSS / JavaScript Tutorial

JavaScript canvas2d object method: strokeRect()

[this page | pdf | back links]

The strokeRect() method of the JavaScript DOM object returned by the getContext("2d") method applied to the HTML <canvas> element draws a rectangle that is not ‘filled’ (i.e. it only draws the edge of the rectangle). The default colour is black, but can be overridden using the strokeStyle property.

 

It has the following syntax with the following parameters.

 

context.strokeRect(x, y, width, height)

 

Parameter

Required / Optional

Description

x

Required

x-coordinate of upper-left corner

y

Required

y-coordinate of upper-left corner

width

Required

Width of rectangle, in pixels

height

Required

Height of rectangle, in pixels

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile