Monday 5 January 2015

html5 canvas tutorials: html5 canvas introduction

html5 canvas tutorial:  introduction

<canvas>
Canvas is a new tag of html introduced in HTML5.As you know all html tags are container , canvas is container for HTML graphics. We can draw graphics such as line,boxes,circle and other shapes on HTML page in canvas
Canvas element has start and close tag .We write canvas element as
<canvas>
</canvas>
Between these two tags our graphics are drawn .Canvas has two attributes height and length.These attribute set the size of canvas on HTML page. Actually we use JavaScript methods (API) to draw graphics. Simplest page with canvas element will be.

how to embed html5 canvas tag in html5 document



    <!DOCTYPE html&gt
    <html>

        <head&gt

            <title&gt

               HTML Canvas  example

            </title>

        </head> 
    
        <body>


          <canvas id ="myCanvas" width ="200" height ="200">

          </canvas >

    
        </body>

    </html>

Save this document as
mycanvas.html
when we see this document in browser .we will see a blank page. Dont worry our canvas is present but hidden. To see canvas we will add style to our canvas. We will modify our Canvas tag as

<canvas width ="200" height ="200" style="border: 1px solid #0000ff;">
</canvas>

Our HTML document in modified form will be.

Modified HTML Document

    <!DOCTYPE html>

    <html>

        <head>

            <title >

             HTML canvas example 

            </title>

        </head>

 
        <body>

            <canvas height="200" width="200" style="border:1px solid #0000ff;>




            </canvas>

        </body >

    </html>



save this page ,and refresh your browser.


Congratulation !
Our canvas in blue color rectangle is present in our web page. We have now canvas and we can draw

No comments:

Post a Comment