- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements