HTML Canvas – First Application

HTML Canvas – First Application ”; Previous Next In the previous chapters we have already seen how to create a Canvas element using the <canvas> tag. Now we will style the Canvas element using simple CSS styles which helps us to understand how the Canvas element is formed. Let us first create an empty Canvas element and style using the following attributes Add background-color Change border Adding background color to the Canvas element Following code demonstrates how to add color to the Canvas element using CSS style attributes. We are using background_color attribute of the Canvas element. The code is given below. <!DOCTYPE html> <html lang=”en”> <head> <title>Canvas Element</title> <style> #canvas{ border:5px solid black; background-color: green; } </style> </head> <body> <canvas id=”canvas” width=”300″ height=”150″ > This text is displayed if your browser does not support HTML5 Canvas or if JavaScript is disabled. </canvas> </body> </html> Output Changing border of the Canvas element By using CSS style attributes, we can change the border style of Canvas element easily. It is useful when creating an interactive visual graphics using Canvas. Following is the implementation of changing the border style of the Canvas element. <!DOCTYPE html> <html lang=”en”> <head> <title>Canvas Element</title> <style> #canvas{ border:2px dotted black; } </style> </head> <body> <canvas id=”canvas” width=”300″ height=”150″ > This text is displayed if your browser does not support HTML5 Canvas or if JavaScript is disabled. </canvas> </body> </html> Output Instead of using solid while creating the Canvas element, we can use one of the following to change the style of the Canvas border per our requirement Dotted Dashed Double Groove Ridge Print Page Previous Next Advertisements ”;

HTML Canvas – Home

HTML Canvas Tutorial PDF Version Video Courses Quick Guide Resources Job Search Canvas is an HTML element that can perform dynamic generation of 2D shapes and bitmap images using JavaScript. HTML Canvas is a great alternative for drawing pictorial data such as graphs, charts, and maps inside a web page. It is a low-level procedural model which updates in the form of a bitmap. The Canvas element is only the basic rectangular-shaped container for graphics, which is usually done using JavaScript. The shapes or any other graphics implementation inside the Canvas element can be done using JavaScript. HTML Canvas element is an HTML tag like the div, a, or table, with the exception that its contents are rendered using JavaScript. Audience This tutorial has been created for the beginners to help them understand the basics of Canvas element. After completing this tutorial, you will find yourself at a moderate level of expertise in Canvas API, from where you can take yourself to the next levels. You will be able to generate various graphic designs useful for creating virtual content, making web-pages interactive and much more. Prerequisites Before proceeding with this tutorial, you should have a basic understanding of Webpages and its programming languages such as HTML, CSS, and JavaScript. Although it is a beginner”s tutorial, we assume that the readers have a good exposure to any front-end programming environment and knowledge of basic concepts such as tags, attributes, and elements. We strongly recommend that you gain some basic knowledge of HTML and JavaScript before proceeding to learn Canvas element. Print Page Previous Next Advertisements ”;