Draw a rectangle. Use a stroke color of red:
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="180" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.strokeStyle = "#FF0000"; ctx.strokeRect(20, 20, 150, 100);//from w ww .j av a 2s .c om </script> </body> </html>
The strokeStyle property sets or gets the color, gradient, or pattern used for strokes.
The strokeStyle property Default value: #000000
context.strokeStyle = color|gradient|pattern;
Property Values
Value | Description |
---|---|
color | A CSS color value that indicates the stroke color of the drawing. Default value is #000000 |
gradient | A gradient object (linear or radial) used to create a gradient stroke |
pattern | A pattern object used to create a pattern stroke |