
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML canvas stroke() Method
The stroke() method of the HTML canvas is used to draw the path. This path is drawn with moveTo() and lineTo() method. The <canvas> element allows you to draw graphics on a web page using JavaScript. Every canvas has two elements that describes the height and width of the canvas i.e. height and width respectively.
Following is the syntax −
ctx.stroke()
Let us now see an example to implement the stroke() method of canvas −
Example
<!DOCTYPE html> <html> <body> <canvas id="newCanvas" width="450" height="350" style="border:2px solid red;"> </canvas> <script> var c = document.getElementById("newCanvas"); var ctx = c.getContext("2d"); ctx.beginPath(); ctx.moveTo(100, 200); ctx.lineTo(100, 100); ctx.strokeStyle = "blue"; ctx.stroke(); ctx.beginPath(); ctx.moveTo(30, 30); ctx.lineTo(20, 100); ctx.lineTo(70, 100); ctx.strokeStyle = "orange"; ctx.stroke(); </script> </body> </html>
Output
- Related Articles
- HTML canvas strokeRect() Method
- HTML canvas clearRect() Method
- HTML canvas fill() Method
- HTML canvas fillRect() Method
- HTML canvas rect() Method
- HTML5 Canvas Text Stroke for Large Font Size
- How to set stroke width of a canvas circle using Fabric.js ?
- HTML canvas Tag
- HTML Canvas Basics
- HTML canvas strokeStyle Property
- HTML canvas fillStyle Property
- HTML canvas shadowColor Property
- HTML canvas shadowOffsetY Property
- HTML canvas shadowBlur Property
- HTML DOM Canvas Object\n

Advertisements