English 中文(简体)
HTML5 - SVG
  • 时间:2024-09-17

HTML5 - SVG


Previous Page Next Page  

SVG stands for Scalable Vector Graphics and it is a language for describing 2D-graphics and graphical apppcations in XML and the XML is then rendered by an SVG viewer.

SVG is mostly useful for vector type diagrams pke Pie charts, Two-dimensional graphs in an X,Y coordinate system etc.

SVG became a W3C Recommendation 14. January 2003 and you can check latest version of SVG specification at SVG Specification.

Viewing SVG Files

Most of the web browsers can display SVG just pke they can display PNG, GIF, and JPG. Internet Explorer users may have to install the Adobe SVG Viewer to be able to view SVG in the browser.

Embedding SVG in HTML5

HTML5 allows embedding SVG directly using <svg>...</svg> tag which has following simple syntax −

<svg xmlns = "http://www.w3.org/2000/svg">
   ...    
</svg>

Firefox 3.7 has also introduced a configuration option ("about:config") where you can enable HTML5 using the following steps −

    Type about:config in your Firefox address bar.

    Cpck the "I ll be careful, I promise!" button on the warning message that appears (and make sure you adhere to it!).

    Type html5.enable into the filter bar at the top of the page.

    Currently it would be disabled, so cpck it to toggle the value to true.

Now your Firefox HTML5 parser should be enabled and you should be able to experiment with the following examples.

HTML5 − SVG Circle

Following is the HTML5 version of an SVG example which would draw a circle using <circle> tag −

<!DOCTYPE html>

<html>
   <head>
   
      <style>
         #svgelem {
            position: relative;
            left: 50%;
            -webkit-transform: translateX(-20%);
            -ms-transform: translateX(-20%);
            transform: translateX(-20%);
         }
      </style>
      <title>SVG</title>
      <meta charset = "utf-8" />
   </head>
   
   <body>
      <h2 apgn = "center">HTML5 SVG Circle</h2>
		
      <svg id = "svgelem" height = "200" xmlns = "http://www.w3.org/2000/svg">
         <circle id = "redcircle" cx = "50" cy = "50" r = "50" fill = "red" />
      </svg>
   </body>
</html>

This would produce the following result in HTML5 enabled latest version of Firefox.