
- 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 strokeRect() Method
The strokeRect() method of the HTML canvas is used to create a rectangle on a web page. 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 −
context.strokeRect(p,q,width,height);
Above,
- p − The x-coordinate of the upper-left corner of the rectangle
- q − The y-coordinate of the upper-left corner of the rectangle
- width − Width of the rectangle
- height − Height of the rectangle
Let us now see an example to implement the strokeStyle property of canvas −
Example
<!DOCTYPE html> <html> <body> <canvas id="newCanvas" width="550" height="400" style="border −2px solid orange;"></canvas> <script> var c = document.getElementById("newCanvas"); var ctx = c.getContext("2d"); ctx.strokeRect(120, 120, 220, 120); </script> </body> </html>
Output
- Related Articles
- HTML canvas clearRect() Method
- HTML canvas fill() Method
- HTML canvas fillRect() Method
- HTML canvas rect() Method
- HTML canvas stroke() Method
- 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
- HTML Canvas to draw Bezier Curve
- Get pixel color from canvas with HTML

Advertisements