HTML5 Canvas

HTML5 has made it very easy to draw graphics on a web page with the help of Javascript. Canvas is actually used as a container of a graphic which has not border and no content in it. Actual graphic is written using Javascript. Now you can not only draw simple graphics but can render game graphics, photo compositions, other visual images on the fly. You can give various effects like coloring, multicoloring figures or text, gradiant etc with the use of canvas.

<canvas> has many attributes like width, height, style, class, id and name which you can use as and when required.

Syntax

<canvas id="canvas1" width="150" height="250">
  graphic code using Javascript will come here...
</canvas>

Browser Support

Almost all latest browsers like Safari, Google Chrome, Mozilla Firefox, Opera, Internet Explorer 9.0 support many HTML5 features and functionalities. The good thing is that now many mobiles web browsers like iPhones, iPads, and Android phones all have excellent support for HTML5.

Canvas Border

The <style> attribute is used to create a border of canvas.

Example

<!DOCTYPE HTML>  
<html>  
<head>  
    <meta charset=UTF-8" />  
    <title>HTML5 Canvas Border Example</title>  
</head>  
<body>
<canvas id="canvas1" width="150" height="150" style="border:2px solid #FF0000;">
</canvas>
</body>
</html>

This will produce following result

Canvas Circle

The ctx.arc() function is used to create circles based on a center points and a radius.

Example

<!DOCTYPE HTML>  
<html>  
<head>  
    <meta charset=UTF-8" />  
    <title>HTML5 Canvas Circle Example</title>  
</head>  
<body>
<canvas id="canvas2" width="200" height="150" style="border:2px solid #FF0000;">
</canvas>
<script>
var c = document.getElementById("canvas2");
var con = c.getContext("2d");
con.beginPath();
con.arc(100,60,50,0,2*Math.PI);
con.fillStyle = 'yellow';
con.fill();
con.stroke();
</script>
</body>
</html>

This will produce following result

See Also

HTML5 Web Storage
HTML5 Audio Tag
HTML5 Video Tag
HTML5 Canvas
HTML5 SVG Tag


 
 
SHARE THIS IF YOU LIKE!
submit to reddit

SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.