What Is HTML SVG Graphics

HTML SVG characterizes vector-based designs in XML design.

What is SVG?

  • Represents Scalable Vector Graphics is a SVG
  • SVG is utilized to characterize designs for the Web
  • Proposal is a e.g SVG

The HTML <svg> Element

The HTML <svg>component is a holder for SVG designs.

SVG has a few techniques for drawing ways, boxes, circles, text, and realistic pictures.

Browser Support

The numbers in the table indicate the main program form that completely upholds the <svg>component.

HTML SVG
HTML SVG

SVG Circle

HTML SVG
Example

<!DOCTYPE html>
<html>
<body>

<svg width=”100″ height=”100″>
  <circle cx=”50″ cy=”50″ r=”40″ stroke=”green” stroke-width=”4″ fill=”yellow” />
</svg>

</body>
</html>

SVG Rectangle

HTML SVG
Example

<svg width=”400″ height=”100″>
  <rect width=”400″ height=”100″ style=”fill:rgb(0,0,255);stroke-width:10;stroke:rgb(0,0,0)” />
</svg>

SVG Rounded Rectangle

HTML SVG
Example

<svg width=”400″ height=”180″>
  <rect x=”50″ y=”20″ rx=”20″ ry=”20″ width=”150″ height=”150″
  style=”fill:red;stroke:black;stroke-width:5;opacity:0.5″ />
</svg>

SVG Star

HTML SVG
Example

<svg width=”300″ height=”200″>
  <polygon points=”100,10 40,198 190,78 10,78 160,198″
  style=”fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;” />
</svg>

SVG Logo

HTML SVG
Example

<svg height=”130″ width=”500″>
  <defs>
    <linearGradient id=”grad1″ x1=”0%” y1=”0%” x2=”100%” y2=”0%”>
      <stop offset=”0%” style=”stop-color:rgb(255,255,0);stop-opacity:1″ />
      <stop offset=”100%” style=”stop-color:rgb(255,0,0);stop-opacity:1″ />
    </linearGradient>
  </defs>
  <ellipse cx=”100″ cy=”70″ rx=”85″ ry=”55″ fill=”url(#grad1)” />
  <text fill=”#ffffff” font-size=”45″ font-family=”Verdana” x=”50″ y=”86″>SVG</text>
</svg>

Differences Between SVG and Canvas

SVG is a language for portraying 2D designs in XML.

Material draws 2D illustrations, on the fly (with a JavaScript).

SVG is XML based, which implies that each component is accessible inside the SVG DOM. You can connect JavaScript occasion overseers for a component.

In SVG, each drawn shape is recognized as an item. In the event that credits of a SVG object are changed, the program can naturally re-render the shape.

Material is delivered pixel by pixel. In material, when the realistic is drawn, it is forgotten by the program. On the off chance that its position ought to be changed, the whole scene should be redrawn, including any articles that may have been covered by the realistic.

Comparison of Canvas and SVG

The table below shows some important differences between Canvas and SVG:

CanvasSVG
Resolution dependentNo support for event handlersPoor text rendering capabilitiesYou can save the resulting image as .png or .jpgWell suited for graphic-intensive gamesResolution independentSupport for event handlersBest suited for applications with large rendering areas (Google Maps)Slow rendering if complex (anything that uses the DOM a lot will be slow)Not suited for game applications