SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software HTML5 Tutorials and HTML 5 Examples
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.

HTML5 Canvas Tutorial for Beginners

HTML5 Canvas tutorial includes basic canvas syntax, sample canvas codes and scripts for drawing in HTML5 canvas. I believe, this Canvas tutorial will be useful to introduce new Canvas API especially for beginners to HTML5.

Let's start the answer of "What is canvas element?".
HTML5 Canvas element is one of new elements introduced with HTML5 which can be used to draw images and graphics on the fly. Canvas element getContext() method returns a context object which provides developers properties and methods to draw 2D graphics using scripting programming including Javascript

The simplest way to create canvas in HTML is adding <canvas> tag in HTML5 page

<canvas id="html5canvas"></canvas>

Adding only canvas element with defining "id" attribute is enough to create a drawing area by scripting in HTML page. By default a canvas with width 300px and height 150px is created by default.

HTML5 canvas element in HTML page

HTML5 programmers can define a canvas as follows using the width and height attribute.

<canvas id="html5canvas" width="500px" height="300px">

Of course for web browser that has lack of HTML5 browser support, it is a good practise to define a fallback code. HTML developers can either provide an HTML content in the fallback section informing the user about the HTML5 support status of his/her internet browser, or display an alternative content without using HTML5 canvas element.

Developers can add fallback HTML code between HTML5 canvas opening tag and canvas closing tag (between <canvas> and </canvas>) Here is a sample.

<canvas id="html5canvas" width="500px" height="300">
Your browser does not have HTML5 browser support.

Using document.getElementById() and the id of the HTML5 canvas as an argument to the getElementById() method, developers can reach canvas within Javascript code dynamically.

var canvas = document.getElementById("html5canvas");

HTML5 Canvas Tutorials and HTML5 Canvas Examples

Here is a list of HTML5 canvas examples and tutorials which web programmers can review for canvas details.

HTML5 Canvas Example - Display Graphics in HTML page
HTML5 Canvas to Image using canvas.toDataURL Method
HTML5 Canvas Load Image into Canvas Element
HTML5 Resize Image in Canvas
How to Draw Stick Man in HTML5 Canvas using Javascript

HTML5 Tutorials
HTML5 Books

70-480 Exam

Copyright © 2004 - 2017 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems