Name

CanvasRenderingContext2D.strokeRect( ): draw a rectangle

Synopsis

void strokeRect(floatx, float y,
                float width, float height)

Arguments

x, y

The coordinates of the upper-left corner of the rectangle.

width, height

The dimensions of the rectangle.

Description

This method draws the outline (but does not fill the interior) of a rectangle with the specified position and size. Line color and line width are specified by the strokeStyle and lineWidth properties. The appearance of the rectangle corners are specified by the lineJoin property.

Current implementations of strokeRect( ) clear the path as if beginPath( ) had been called. This surprising behavior may not be standardized and should not be relied upon.

See Also

CanvasRenderingContext2D.fillRect( )
CanvasRenderingContext2D.lineJoin
CanvasRenderingContext2D.rect( )
CanvasRenderingContext2D.stroke( )

Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.