YouTip LogoYouTip

Prop Canvas Strokestyle

# HTML canvas strokeStyle Property [![Image 9: Canvas Object Reference](#) Canvas Object](#) ## Example Draw a rectangle. Use a red stroke color: YourbrowserdoesnotsupporttheHTML5canvastag. JavaScript: var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.strokeStyle="#FF0000"; ctx.strokeRect(20,20,150,100); [Try it Β»](#) * * * ## Browser Support ![Image 10: Internet Explorer](#)![Image 11: Firefox](#)![Image 12: Opera](#)![Image 13: Google Chrome](#)![Image 14: Safari](#) The strokeStyle property is supported in Internet Explorer 9, Firefox, Opera, Chrome, and Safari. **Note:** Internet Explorer 8 and earlier versions do not support the element. * * * ## Definition and Usage The strokeStyle property sets or returns the color, gradient, or pattern used for strokes. | Default Value: | #000000 | | --- | | JavaScript Syntax: | _context_.strokeStyle=_color_|_gradient_|_pattern_; | ## Property Values | Value | Description | | --- | --- | | _color_ | A (#) that indicates the stroke color of the drawing. The default value is #000000. | | _gradient_ | A gradient object ((#) or (#)) used to fill the drawing. | | _pattern_ | A (#) object used to create a pattern stroke. | * * * ![Image 15: Example](#) ## More Examples ## Example Draw a rectangle. Use a gradient stroke: YourbrowserdoesnotsupporttheHTML5canvastag. JavaScript: var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); var gradient=ctx.createLinearGradient(0,0,170,0); gradient.addColorStop("0","magenta"); gradient.addColorStop("0.5","blue"); gradient.addColorStop("1.0","red"); // Fill with gradient ctx.strokeStyle=gradient; ctx.lineWidth=5; ctx.strokeRect(20,20,150,100); [Try it Β»](#)
← Prop Canvas ShadowcolorProp Canvas Fillstyle β†’