AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML SVG Graphics

Tutorial HTML SVG Graphics



Free Tutorial HTML SVG Graphics

HTML Graphics


This lesson covers SVG's main tag, the <svg> tag. Basic SVG shapes (lines, rectangles, circles, curves, etc.) are discussed in the Basic SVG Shapes lesson. Some more advanced shapes are discussed in the SVG Advanced Shapes lesson. The SVG lesson (2) covers other aspects of SVG images.

What you should already know

Before you continue, you should have some basic understanding of the following:

What is SVG
SVG (Scalable Vector Graphics = Scalable Vector Graphics) is a markup language created by the W3C and aimed at the representation of vector graphics (drawings and text).

SVG recommendations published or in preparation by the W3C are discussed in the Lesson on History of the Web.

In a vector graphic, the elements of the image are defined as elementary shapes (lines, rectangles, circles, curves, polygons, etc.), defined by tags similar to those in HTML. For this reason SVG is not a suitable format for photographs, but it is suitable for any type of drawing, technical or artistic.

The advantages of SVG are many:

1. SVG images can be enlarged to any scale without losing quality, since they are defined as shapes that the browser draws with the necessary precision.
2. SVG images tend to take up little space as they are defined by labels. The size in KB of the image is also independent of the size with which it is seen on the web page.
3. Images can be easily reused and combined as it is enough to copy the source code from one image to another.
4. Images can be dynamically modified using style sheets or javascript because they are part of the web page.
An SVG graphic can be included on a web page in two ways, as an internal object or as an external object.

You can embed SVG elements directly into your HTML pages.

The SVG plane

El plano SVG - SVG drawings are defined in an infinite plane in which the Y-axis is oriented downward, as shown in the following drawing, which shows the coordinate axes, four points in red, and their coordinates.

Y X (100, 100) (100, -100) (-100, -100) (-100, 100)

 

Example: SVG Circle - <circle> a simple code, change parameters
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="400" height="400" viewBox="-200 -200 400 400" style="background-color: #eeeeee">
<line x1="-200" y1="0" x2="200" y2="0" stroke="black" stroke-width="1" />
<line x1="0" y1="-200" x2="0" y2="200" stroke="black" stroke-width="1" />
<text x="10" y="190" font-family="sans-serif" font-size="20" fill="black">Y</text>
<polyline points="-5,190 0,200 5,190" fill="none" stroke-width="1" stroke="black" />
<text x="180" y="-10" font-family="sans-serif" font-size="20" fill="black">X</text>
<polyline points="190,5 200,0 190,-5" fill="none" stroke-width="1" stroke="black" />
<polygon points="100,100 -100,100 -100,-100, 100,-100" fill="none" stroke-width="1" stroke="black" stroke-dasharray="5,5" />
<circle cx="100" cy="100" r="4" fill="red" />
<text x="105" y="120" font-family="sans-serif" font-size="18" fill="black">(100, 100)</text>
<circle cx="100" cy="-100" r="4" fill="red" />
<text x="105" y="-105" font-family="sans-serif" font-size="18" fill="black">(100, -100)</text>
<circle cx="-100" cy="-100" r="4" fill="red" />
<text x="-105" y="-105" font-family="sans-serif" font-size="18" fill="black" text-anchor="end">(-100, -100)</text>
<circle cx="-100" cy="100" r="4" fill="red" />
<text x="-105" y="120" font-family="sans-serif" font-size="18" fill="black" text-anchor="end">(-100, 100)</text>
</svg>

 


 

SVG Circle - <circle>



Example: SVG Circle - <circle> a simple code, change parameters
<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
Sorry, your browser does not support inline SVG.
</svg>

 



Example: a simple code, change parameters
<svg
width="100" height="100" viewBox="-50 -50 100 100"
style="background-color: lightgray">
<circle cx="0" cy="0" r="50" fill="none" stroke="red" stroke-width="1" />

 


 

SVG <ellipse>


An ellipse is closely related to a circle. The difference is that an ellipse has an x and a y radius that differs from each other, while a circle has equal x and y radius:

Here is the SVG code:

Example: SVG <ellipse> a simple code, change parameters
<svg height="140" width="360">
<ellipse cx="200" cy="80" rx="100" ry="50"
style="fill:green;stroke:purple;stroke-width:2" />
</svg>

 


 

SVG <line>

 


 

SVG <polygon>

 


 

SVG <polyline>

 


 

SVG <path>

 


 

SVG <text>

Overlapping elements 1

Overlapping elements

Imágenes SVG

SVG Radial Gradient - <radialGradient>

 

 





    Could not connect: Access denied for user 'u142985959_ager'@'localhost' (using password: YES)