Google News
logo
HTML5 - Interview Questions
Explain HTML5 Graphics.
HTML5 supports two types of graphics i.e. Canvas and SVG.
 
a) Canvas : <canvas> element is used to design graphics on the web page, and it has several methods available for drawing circles, boxes, adding images and text. 300 px X 150 px (width X height) is the default pixel size of canvas.
 
Example to Draw square Box using canvas element is shown below.
 
<!DOCTYPE HTML>
<html>
  <head>
   <style>
    #mycanvas{border:2px solid pink;}
   </style>
  </head>
  <body>
    <canvas id = “mycanvas” width = “150” height = “150”></canvas>
  </body>
</html>
 
b) SVG : <svg> Scalable Vector Graphics, are mostly used for graphical application and scalable vector type diagrams, such as X, Y coordinate system, two-dimensional and pie charts. This makes it faster and lightweight. SVG follows XML format.
 
Example to draw a Rectangle using SVG element is shown below.
 
<!DOCTYPE html>
<html>
  <body>
     <svg width = “400” height = “150”>
       <rect width = “400” height = “150” style = “fill:rgb(200,220,255);stroke-width:10;stroke:rgb(0,0,0)”/>
     </svg>
  </body>
</html>
Advertisement