html
  1. html-svg-tag

HTML <svg> Tag

  • The HTML <svg> tag defines a scalable vector graphic in an HTML document.
  • This tag is used to create vector graphics on the web that can be scaled and resized without losing their quality. <svg> stands for Scalable Vector Graphics.

Syntax

The basic syntax for using the <svg> tag is as follows:

<svg width="px" height="px">
   <shape attribute="value" />
   ...
</svg>

Here, width and height specify the dimensions of the <svg> element in pixels. The next lines define various shapes (rectangles, circles, paths, etc.) using their respective SVG shape elements.

Example

Here's an example of a basic SVG image using the <svg> tag:

<svg width="100" height="100">
   <rect x="10" y="10" width="80" height="80" />
</svg>
Try Playground

Explanation

The <svg> tag is used to draw various shapes, such as lines, rectangles, circles, polygons, and paths by defining them in the SVG markup. The attributes such as width, height and viewbox can be used to define the size and aspect ratio of the SVG image. SVG images are created using XML tags, which define the shape, size, and properties of the element being created.

Use

The <svg> tag is used to create vector graphics in an HTML document that can be scaled and resized without sacrificing quality. SVG graphics can be used for logos, icons, and other visual elements on web pages.

Important Points

  • The <svg> tag has a wider range of styling options compared to traditional HTML tags.
  • SVG images can be animated and manipulated using JavaScript.
  • SVG graphics are resolution-independent and can be scaled without losing their quality.
  • The viewbox attribute can be used to define the visible area of the image.

Summary

In summary, the HTML <svg> tag is used to create scalable vector graphics in HTML documents that can be resized without losing quality. Vector graphics offer the advantage of not losing quality even when resized, hence are ideal for logos, icons, and other visual elements on web pages.

Published on: