HTML SVG

HTML SVG (Scalable Vector Graphics) is a markup language for describing two-dimensional vector graphics. It allows you to create and display vector-based graphics on web pages. SVG graphics are resolution-independent, meaning they can be scaled to any size without losing quality.


To use SVG in HTML, you can embed SVG markup directly into your HTML document using the `<svg>` tag. Here's an example of a simple SVG circle:


html
<svg width="200" height="200">
    <circle cx="100" cy="100" r="50" fill="red" />
</svg>

In the above example, we define an SVG element with a width and height of 200 units. Inside the SVG element, we use the `<circle>` element to draw a circle. The `cx` and `cy` attributes specify the center coordinates of the circle, and the `r` attribute sets the radius. The `fill` attribute determines the fill color of the circle.

SVG provides a wide range of elements and attributes for creating various shapes, paths, gradients, text, and more. You can combine these elements and apply styling and transformations to create complex graphics.


Here's an example that demonstrates a more complex SVG graphic with multiple elements:

html
<svg width="400" height="300">
    <rect x="50" y="50" width="200" height="150" fill="blue" />
    <circle cx="150" cy="125" r="50" fill="yellow" />
    <text x="200" y="200" fill="white" font-size="24" text-anchor="middle">Hello SVG!</text>
</svg>

In the above example, we draw a blue rectangle using the `<rect>` element, a yellow circle using the `<circle>` element, and white text using the `<text>` element. The `x` and `y` attributes define the position of the elements, and other attributes control their size, color, and text properties.

SVG graphics can also be manipulated and animated using JavaScript and CSS. You can interact with SVG elements, change their attributes, and apply animations and transitions to create dynamic and responsive visuals.

It's important to note that SVG is different from the HTML canvas element discussed earlier. SVG is based on XML and describes graphics using vector shapes and elements, while the canvas element provides a bitmap-based drawing surface for rendering graphics using JavaScript. The choice between SVG and the canvas depends on the specific requirements of your project.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext