{"id":15458,"date":"2016-12-20T16:15:33","date_gmt":"2016-12-20T14:15:33","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=15458"},"modified":"2017-12-19T13:43:35","modified_gmt":"2017-12-19T11:43:35","slug":"html5-canvas-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/","title":{"rendered":"HTML5 Canvas Example"},"content":{"rendered":"<p>In this example we are going to learn about HTML5 canvas. Canvas was added to HTML in HTML5. HTML5 canvas is a powerful tool (or container) that is used for drawing images and shapes.<br \/>\nFor this example we will use:<\/p>\n<ul>\n<li>A computer with a modern browser installed<\/li>\n<li>notepad++<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;tgm4cmEWcKUikZNn&#8217;]<\/p>\n<h2>1. What Is HTML\/HTML5<\/h2>\n<p>HTML is an abbreviation for Hypertext MarkUp Language and is used to describe a webpage. Combining HTML with JavaScript and CSS allows you to do a lot.<\/p>\n<p>CSS allows you to style a webpage and it stands for cascading style sheets. CSS describes how HTML elements should be displayed.<\/p>\n<p>JavaScript is used\u00a0to program the behavior of web pages. JavaScript makes a webpage interactive.<\/p>\n<p>HTML5 is the fifth and latest version of the HTML standard. HTML5 has added a lot of capabilities to HTML \u00a0that simplifies the life of a lot of web developers.<\/p>\n<h3>1.1 What Is HTML5 Canvas<\/h3>\n<p>HTML5 canvas combined with JavaScript is used to do a lot of things, from drawing, setting transparency levels on images to even animations and game development.<br \/>\nCanvas is a rectangular area on an HTML page. By default, a canvas has no border and no content.<\/p>\n<pre class=\"brush:bash\">&lt;canvas&gt;\r\n&lt;\/canvas&gt;\r\n\r\n<\/pre>\n<p>You can create an HTML5 canvas by using the tag above. You can also set the width and height of the canvas within its tag or you can do it with JavaScript. Lets look at the example below:<\/p>\n<pre class=\"brush:bash\">&lt;canvas width=500 height=500 &gt;\r\n&lt;\/canvas&gt;\r\n\r\n<\/pre>\n<p>To set the width and height through JavaScript we have to set an ID on our tag.<\/p>\n<pre class=\"brush:bash\">&lt;canvas id=board &gt;\r\n&lt;\/canvas&gt;\r\n\r\n<\/pre>\n<p><b>NOTE: <\/b> It is also possible to create HTML5 canvas element on the fly with JavaScript <code>document.createElement()<\/code> function.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt; \r\n&lt;html lang=en&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML5 canvas test&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n\t&lt;body onload=init()&gt;\r\n&lt;script&gt;\r\nfunction init(){\r\nvar canvas=document.getElementById(\"board\");\r\ncanvas.width=document.body.clientWidth;\r\ncanvas.height=document.body.clientHeight;\r\n\r\n\r\n}\r\n\r\n&lt;\/script&gt;\r\n\t\r\n\t&lt;canvas id=board&gt;\r\n\t\r\n\t&lt;\/canvas&gt;\r\n\r\n\t&lt;\/body&gt;\r\n\t&lt;\/html&gt;\r\n<\/pre>\n<p>In the script above we get the canvas element and sets its width and height.<\/p>\n<h3>1.1 HTML5 Canvas Context<\/h3>\n<p>To draw on our canvas we need to get the canvas context. Lets do this in the next script.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index2.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt; \r\n&lt;html lang=en&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML5 canvas test&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n\t&lt;body onload=init()&gt;\r\n&lt;script&gt;\r\nfunction init(){\r\nvar canvas=document.getElementById(\"board\");\r\ncanvas.width=document.body.clientWidth;\r\ncanvas.height=document.body.clientHeight;\r\ncon=canvas.getContext(\"2d\");\r\n\r\n}\r\n\r\n&lt;\/script&gt;\r\n\t\r\n\t&lt;canvas id=board&gt;\r\n\t\r\n\t&lt;\/canvas&gt;\r\n\r\n\t&lt;\/body&gt;\r\n\t&lt;\/html&gt;\r\n<\/pre>\n<p>In line 28 we get the 2d context for drawing.<br \/>\n<b>Note: <\/b> Normally we should write our JavaScript in a different file and link to it from our HTML file. This makes our code modular. It is also easier to re-use and maintain the code.<\/p>\n<h3>Drawing A Rectangle<\/h3>\n<p>Lets draw a rectangle on our canvas.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index3.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt; \r\n&lt;html lang=en&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML5 canvas test&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n\t&lt;body onload=init()&gt;\r\n&lt;script&gt;\r\nfunction init(){\r\nvar canvas=document.getElementById(\"board\");\r\ncanvas.width=document.body.clientWidth;\r\ncanvas.height=document.body.clientHeight;\r\ncon=canvas.getContext(\"2d\");\r\ncon.strokeStyle=\"#000000\";\r\ncon.strokeRect(20,20,150,100);\r\n}\r\n\r\n&lt;\/script&gt;\r\n\t\r\n\t&lt;canvas id=board&gt;\r\n\t\r\n\t&lt;\/canvas&gt;\r\n\r\n\t&lt;\/body&gt;\r\n\t&lt;\/html&gt;\r\n\r\n\r\n\r\n\r\n<\/pre>\n<p>In line 29 and 30 we set the strokestyle color and we draw the rect.<\/p>\n<pre class=\"brush:bash\">canvas.getContext(\"2d\").stokeRect(x,y,w,h);\r\n\r\n<\/pre>\n<p>The parameter x is the x coordinate for rectangle.<br \/>\nThe parameter y is the y coordinate for rectangle.<br \/>\nThe parameter w is the width of the rectangle.<br \/>\nThe parameter h is the height of rectangle.<br \/>\nLets fill the rectangle with a color. We do this in the script below.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index4.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt; \r\n&lt;html lang=en&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML5 canvas test&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n\t&lt;body onload=init()&gt;\r\n&lt;script&gt;\r\nfunction init(){\r\nvar canvas=document.getElementById(\"board\");\r\ncanvas.width=document.body.clientWidth;\r\ncanvas.height=document.body.clientHeight;\r\ncon=canvas.getContext(\"2d\");\r\ncon.fillStyle=\"#000000\";\r\ncon.fillRect(20,20,150,100);\r\n}\r\n\r\n&lt;\/script&gt;\r\n\t\r\n\t&lt;canvas id=board&gt;\r\n\t\r\n\t&lt;\/canvas&gt;\r\n\r\n\t&lt;\/body&gt;\r\n\t&lt;\/html&gt;\r\n<\/pre>\n<h3>Drawing A Circle<\/h3>\n<p>Lets draw a circle on our canvas. To draw a circle we use the arc method.<\/p>\n<pre class=\"brush:bash\">canvas.getContext(\"2d\").arc(x,y,r,start,end,clockwise);\r\n\r\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>index5.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt; \r\n&lt;html lang=en&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML5 canvas test&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n\t&lt;body onload=init()&gt;\r\n&lt;script&gt;\r\nfunction init(){\r\nvar canvas=document.getElementById(\"board\");\r\ncanvas.width=document.body.clientWidth;\r\ncanvas.height=document.body.clientHeight;\r\ncon=canvas.getContext(\"2d\");\r\ncon.fillStyle=\"#000000\";\r\ncon.beginPath();\r\ncon.arc(100,75,50,0,2*Math.PI);\r\ncon.stroke();\r\n}\r\n\r\n&lt;\/script&gt;\r\n\t\r\n\t&lt;canvas id=board&gt;\r\n\t\r\n\t&lt;\/canvas&gt;\r\n\r\n\t&lt;\/body&gt;\r\n\t&lt;\/html&gt;\r\n<\/pre>\n<p>x represents the x coordinate of the center circle.<br \/>\ny represents the y coordinate of the center circle.<br \/>\nr is the radius of the circle.<br \/>\nStart is the starting angle of the circle.<br \/>\nEnd is the ending angle of the circle.<br \/>\nClockwise specifies whether the drawing should be counterclockwise or clockwise. False is default and it is optional.<\/p>\n<h3>Drawing An Image On HTML5 Canvas<\/h3>\n<p><span style=\"text-decoration: underline;\"><em>index6.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt; \r\n&lt;html lang=en&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML5 canvas test&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n\t&lt;body onload=init()&gt;\r\n&lt;script&gt;\r\nI = new Image();\/\/create an image object\r\nI.src=\"x.png\";\/\/ load the image\r\nfunction init(){\r\nvar canvas=document.getElementById(\"board\");\r\ncanvas.width=document.body.clientWidth;\r\ncanvas.height=document.body.clientHeight;\r\ncon=canvas.getContext(\"2d\");\/\/ get the 2d context\r\ncon.drawImage(I, 0,0);\/\/ draw the image\r\n}\r\n\r\n&lt;\/script&gt;\r\n\t\r\n\t&lt;canvas id=board&gt;\r\n\t\r\n\t&lt;\/canvas&gt;\r\n\r\n\t&lt;\/body&gt;\r\n\t&lt;\/html&gt;\r\n\r\n<\/pre>\n<p>Lets see another variable of the draw image method<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index7.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt; \r\n&lt;html lang=en&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML5 canvas test&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n\t&lt;body onload=init()&gt;\r\n&lt;script&gt;\r\nI = new Image();\/\/create an image object\r\nI.src=\"x.png\";\/\/ load the image\r\nfunction init(){\r\nvar canvas=document.getElementById(\"board\");\r\ncanvas.width=document.body.clientWidth;\r\ncanvas.height=document.body.clientHeight;\r\ncon=canvas.getContext(\"2d\");\r\ncon.drawImage(I, 0,0,I.width\/2,I.height,10,10,I.width\/2,I.height);\/\/ another variation of the draw method used to draw part of the image\r\n}\r\n\r\n&lt;\/script&gt;\r\n\t\r\n\t&lt;canvas id=board&gt;\r\n\t\r\n\t&lt;\/canvas&gt;\r\n\r\n\t&lt;\/body&gt;\r\n\t&lt;\/html&gt;\r\n<\/pre>\n<p>This particular draw method takes 8 parameters.<\/p>\n<pre class=\"brush:bash\">context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height );\r\n\r\n<\/pre>\n<p>img is the image to draw.<br \/>\nsx is the x coordinate of the image to draw.<br \/>\nsy is the is the y coordinate of the image to draw<br \/>\nswidth is the width of the image.<br \/>\nsheight is the height of the image.<br \/>\nx is the x coordinate of where to place the image on the canvas<br \/>\ny is the y coordinate of where to place the image on the canvas<br \/>\nwidth is the width of the image to use<br \/>\nheight is the height of the image to use.<\/p>\n<h2>2. Summary<\/h2>\n<p>In this example we learnt about the HTML5 canvas. What it is and how to use it. We learnt how to draw a rectangle, a circle and images on the HTML5 canvas.<\/p>\n<h2>3. Download the source code<\/h2>\n<div class=\"download\">\n<p><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here:\u00a0<strong><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/12\/html5canvasexample.zip\">html5canvasexample<\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example we are going to learn about HTML5 canvas. Canvas was added to HTML in HTML5. HTML5 canvas is a powerful tool (or container) that is used for drawing images and shapes. For this example we will use: A computer with a modern browser installed notepad++ &nbsp; &nbsp; &nbsp; &nbsp; [ulp id=&#8217;tgm4cmEWcKUikZNn&#8217;] 1. &hellip;<\/p>\n","protected":false},"author":164,"featured_media":914,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[38,58],"class_list":["post-15458","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html5","tag-canvas","tag-html5-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HTML5 Canvas Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this example we are going to learn about HTML5 canvas. Canvas was added to HTML in HTML5. HTML5 canvas is a powerful tool (or container) that is used\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HTML5 Canvas Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this example we are going to learn about HTML5 canvas. Canvas was added to HTML in HTML5. HTML5 canvas is a powerful tool (or container) that is used\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-20T14:15:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-19T11:43:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Olayemi Odunayo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Olayemi Odunayo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/\"},\"author\":{\"name\":\"Olayemi Odunayo\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8\"},\"headline\":\"HTML5 Canvas Example\",\"datePublished\":\"2016-12-20T14:15:33+00:00\",\"dateModified\":\"2017-12-19T11:43:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/\"},\"wordCount\":681,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"keywords\":[\"Canvas\",\"html5\"],\"articleSection\":[\"HTML5\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/\",\"name\":\"HTML5 Canvas Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"datePublished\":\"2016-12-20T14:15:33+00:00\",\"dateModified\":\"2017-12-19T11:43:35+00:00\",\"description\":\"In this example we are going to learn about HTML5 canvas. Canvas was added to HTML in HTML5. HTML5 canvas is a powerful tool (or container) that is used\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTML5\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/html5\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"HTML5 Canvas Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8\",\"name\":\"Olayemi Odunayo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g\",\"caption\":\"Olayemi Odunayo\"},\"description\":\"I am a programmer and web developer, who has experience in developing websites and writing desktop and mobile applications. I have worked with both schematic and schemaless databases. I am also familiar with third party API and working with cloud servers. I do programming on the client side with Java, JavaScript, html, Ajax and CSS while I use PHP for server side programming.\",\"sameAs\":[\"https:\/\/www.webcodegeeks.com\/\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/olayemi-odunayo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTML5 Canvas Example - Web Code Geeks - 2026","description":"In this example we are going to learn about HTML5 canvas. Canvas was added to HTML in HTML5. HTML5 canvas is a powerful tool (or container) that is used","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/","og_locale":"en_US","og_type":"article","og_title":"HTML5 Canvas Example - Web Code Geeks - 2026","og_description":"In this example we are going to learn about HTML5 canvas. Canvas was added to HTML in HTML5. HTML5 canvas is a powerful tool (or container) that is used","og_url":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-12-20T14:15:33+00:00","article_modified_time":"2017-12-19T11:43:35+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","type":"image\/jpeg"}],"author":"Olayemi Odunayo","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Olayemi Odunayo","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/"},"author":{"name":"Olayemi Odunayo","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8"},"headline":"HTML5 Canvas Example","datePublished":"2016-12-20T14:15:33+00:00","dateModified":"2017-12-19T11:43:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/"},"wordCount":681,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","keywords":["Canvas","html5"],"articleSection":["HTML5"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/","url":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/","name":"HTML5 Canvas Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","datePublished":"2016-12-20T14:15:33+00:00","dateModified":"2017-12-19T11:43:35+00:00","description":"In this example we are going to learn about HTML5 canvas. Canvas was added to HTML in HTML5. HTML5 canvas is a powerful tool (or container) that is used","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-canvas-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"HTML5","item":"https:\/\/www.webcodegeeks.com\/category\/html5\/"},{"@type":"ListItem","position":3,"name":"HTML5 Canvas Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8","name":"Olayemi Odunayo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g","caption":"Olayemi Odunayo"},"description":"I am a programmer and web developer, who has experience in developing websites and writing desktop and mobile applications. I have worked with both schematic and schemaless databases. I am also familiar with third party API and working with cloud servers. I do programming on the client side with Java, JavaScript, html, Ajax and CSS while I use PHP for server side programming.","sameAs":["https:\/\/www.webcodegeeks.com\/"],"url":"https:\/\/www.webcodegeeks.com\/author\/olayemi-odunayo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/15458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/164"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=15458"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/15458\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/914"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=15458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=15458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=15458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}