Home > Article > Web Front-end > HTML5 Inline SVG Tutorial and Differences from Canvas
What is SVG?
SVG stands for Scalable Vector Graphics#SVG is used to define vector-based graphics for the web
SVG usageXML
Format definition graphicsSVG images will not lose their graphic quality when enlarged or changed in size
SVG is a standard of the World Wide Web ConsortiumSVG AdvantagesCompared with other image formats (such as JPEG and GIF), the advantages of using SVG are: SVG images can be created and modified through a text editorSVG images can be searched, indexed, scripted or compressedSVG is scalableSVG images can be printed with high quality at any resolution SVG can be enlarged without losing image qualityBrowser supportInternet Explorer 9+, Firefox, Opera,Chr
ome, and Safari support inline SVG.Embed SVG directly into HTML pages
InHTML5
, you can embed SVG elements directly into HTML pages:<!DOCTYPE html> <html> <body> <svg xmlns="www.php.cn/2000/svg" version="1.1" height="190"> <polygon points="100,10 40,180 190,60 10,60 160,180" style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;"> </svg> </body> </html>Result:Sorry, your browser does not support inline SVG.To learn more about SVG tutorials, please visit SVG Tutorials.SVG vs. ##Canvas
The difference between the two
SVG is a language that uses XML to describe 2D graphics. Canvas uses
JavaScriptto draw 2D graphics.
SVG is based on XML, which means every element in the SVG DOM is available. You can attach a JavaScript event handler to an element.
In SVG, each drawn graphic is considered an object. If the SVG object's
propertieschange, the browser can automatically reproduce the graphic. Canvas is rendered pixel by pixel. In canvas, once a graphic is drawn, it no longer gets the browser's attention. If its position changes, the entire scene needs to be redrawn, including any objects that may have been covered by graphics. 【Related Recommendations】
1.
Special Recommendation
:"php Programmer Toolbox" V0.1 version Download 2. Free h5 online video tutorial
##3. php.cn original html5 video tutorial
The above is the detailed content of HTML5 Inline SVG Tutorial and Differences from Canvas. For more information, please follow other related articles on the PHP Chinese website!