offline version v3


253 of 264 menu

strokeStyle property

The strokeStyle property sets the color of a line when drawn on the canvas. The value of the property is any CSS units for color.

Syntax

context.strokeStyle = color;

Example

Let's draw a stroke with rect and color it red:

<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas> let canvas = document.querySelector('#canvas'); let ctx = canvas.getContext('2d'); ctx.rect(50, 50, 100, 100); ctx.strokeStyle = 'red'; ctx.stroke();

:

See also

  • the fillStyle method
    that sets the background color of a shape
enru