Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

HTML5 Inline SVG


May 03, 2021 HTML5


Table of contents


HTML5 Inline SVG

SVG represents scalable vector graphics, which are based on extensable markup languages (a subset of standard common markup languages) and are used to describe a graphical format for two-dimensional vector graphics, which became the W3C recommendation on January 14, 2003.

HTML5 supports inline SVG.

HTML5 Inline SVG


What is SVG?

  • SVG refers to scalable vector graphics (Scalable Vector Graphics)

  • SVG is used to define vector-based graphics for networks

  • SVG uses the XML format to define graphics

  • SVG images do not lose their graphic quality when zoomed in or changed in size

  • SVG is the standard of the World Wide Web Alliance

  • SVG is a whole with W3C standards such as DOM and XSL


SVG benefits

Compared to other image formats, such as JPEG and GIF, the advantages of using SVG are:

  • SVG images can be created and modified through the text editor

  • SVG images can be searched, indexed, scripted, or compressed

  • The SVG is scalable

  • SVG images can be printed at any resolution with high quality

  • SVG can be magnified without decreasing image quality


Browser support

HTML5 Inline SVG HTML5 Inline SVG HTML5 Inline SVG HTML5 Inline SVG HTML5 Inline SVG

Internet Explorer 9 Plus, Firefox, Opera, Chrome, and Safari support inline SVG.


Embed SVG directly into the HTML page

In HTML5, you can embed SVG elements directly into HTML pages:

<!DOCTYPE html>
<html>
<body>

<svg xmlns="http://www.w3.org/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>

Try it out . . .

To learn more about the SVG tutorial, visit the SVG tutorial .


The difference between SVG and Canvas

SVG is a language that uses XML to describe 2D graphics.

Canvas draws 2D graphics using JavaScript.

SVG is based on XML, which means that every element in the SVG DOM is available. You can attach a JavaScript event processor to an element.

In SVG, each drawing is treated as an object. If the properties of the SVG object change, the browser can automatically reproduce the graphic.

Canvas is rendered pixel by pixel. I n canvas, once the graphic is drawn, it does not continue to receive browser attention. If its position changes, the entire scene also needs to be redrawn, including any objects that might have been covered by the drawing.


Canvas's comparison with SVG

The following table lists some of the differences between canvas and SVG.

Canvas SVG
  • Dependency resolution

  • Event processor does not support

  • Weak text rendering ability

  • Can save results images in .png or .jpg format

  • Most suitable for image-intensive games, many of which will be redrawn frequently

  • Redependent resolution

  • Support event processor

  • Ultimate application with large rendering zones (such as Google Maps)

  • High complexity will slow down the rendering speed (any excessive use of DOM is not fast)

  • Not suitable for game applications