Both canvas and svg can create graphics on the browser. Therefore, canvas and svg feel very similar in HTML5, but in fact canvas and svg are fundamentally different. The following PHP Chinese website summarizes the differences between canvas and svg by comparing the differences between canvas and svg. Let’s take a look together.
Before talking about the difference between canvas and svg, let’s first take a look at what canvas and svg are?
What is svg?
SVG stands for Scalable Vector Graphics.
SVG is used to define vector-based graphics for use on the web.
SVG uses XML format to define graphics.
SVG images can be enlarged or resized without losing graphic quality.
SVG is a World Wide Web Consortium standard.
SVG is integrated with W3C standards such as DOM and XSL.
What is canvas?
HTML5’s canvas element uses JavaScript to draw images on a web page. The canvas is a rectangular area that you can control every pixel of. canvas has many ways to draw paths, rectangles, circles, characters, and add images.
After knowing what svg and canvas are, let’s compare canvas and svg.
Comparison of the differences between canvas and svg:
First of all, let’s look at the difference between canvas and svg in terms of time:
Canvas is a new element
SVG is not a proprietary tag of HTML5. Initially, SVG is a language that uses XML technology (Hypertext Extension Language, which can customize tags or attributes) to describe two-dimensional graphics.
Secondly, let’s look at the functional difference between canvas and svg:
SVG is a language that uses XML to describe 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 properties of an SVG object change, the browser can automatically reproduce the graphic.
Canvas draws 2D graphics through JavaScript.
Canvas is rendered pixel by pixel.
In canvas, once a graphic is drawn, it will no longer receive 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.
Finally, let’s look at the comparison between canvas and svg technology applications:
Canvas does not depend on resolution.
Canvas supports event handlers.
Canvas is best suited for applications with large rendering areas (such as Google Maps).
High canvas complexity will slow down rendering (any application that overuses the DOM is not fast).
canvas is not suitable for game applications.
svg depends on resolution.
svg does not support event handlers.
svg has weak text rendering capabilities.
svg can save the resulting image in .png or .jpg format.
svg is best suited for graphics-intensive games where many objects will be redrawn frequently.
This article ends here. For more knowledge about canvas and svg, please refer to HTML5 Development Manual.
The above is the detailed content of What is the difference between canvas and svg? Comparison of the differences between canvas and svg. For more information, please follow other related articles on the PHP Chinese website!