Advertisement
Home Open Editor ❯

HTML canvas strokeStyle Property

Example

// Accessing the element
let c = document.getElementById("myCanvas");

// Styling canvas
let ctx = c.getContext("2d");
ctx.strokeStyle = "red";
ctx.strokeRect(25, 25, 100, 100);

Try this code ❯

Meaning

The strokeStyle canvas property sets or returns the color, gradient, or pattern used for strokes.


Standard Syntax

Default value:

#000000

JavaScript syntax:

context.strokeStyle=color|gradient|pattern;


Advertisement

Property Values

Value Description
color Specifies a CSS color value that the stroke color of the drawing. Default value is #000000
gradient Specifies a gradient object to stroke the drawing.
pattern Specifies a pattern object to use to stroke the drawing.
Home Open Editor ❯
Advertisement